tags:

views:

40

answers:

4

Hi I need help with the syntax on this code:

IF OBJECT_ID('TEMPDB..#LTS_MAP') IS NOT NULL
BEGIN DROP TABLE #LTS_MAP END


SELECT
dtMicIssue as  LATE_CHARGE_FACTOR
,CASE   
WHEN (dtMicIssue is NOT NULL) AND (dtMicIssue  <> '1900-01-01 00:00:00') 
 THEN CONVERT(SMALLDATETIME,dtMicIssue)  
     ELSE NULL END 


INTO    #LTS_MAP
FROM    SBAURSQL001.LTSArchive.dbo.LoanMaster_0609

receiving error: Msg 8155, Level 16, State 1, Line 5 No column was specified for column 2 of '#LTS_MAP'.

Trying to combine case functionality with select of the dtMicIssue and messing up on the syntax...

+2  A: 

Exactly what it says

Every column needs a name in the table #LTS_MAP that you are creating...

SELECT
dtMicIssue as  LATE_CHARGE_FACTOR
,CASE   
WHEN (dtMicIssue is NOT NULL) AND (dtMicIssue  <> '1900-01-01 00:00:00') 
 THEN CONVERT(SMALLDATETIME,dtMicIssue)  
     ELSE NULL END  AS SomethingMeaningfulHere   --you're missing this: a column name!


INTO    #LTS_MAP
FROM    SBAURSQL001.LTSArchive.dbo.LoanMaster_0609
gbn
+1  A: 

You need to alias the CASE Statement so that it has a column name:

IF OBJECT_ID('TEMPDB..#LTS_MAP') IS NOT NULL
BEGIN DROP TABLE #LTS_MAP END


SELECT
dtMicIssue as  LATE_CHARGE_FACTOR
,CASE   
WHEN (dtMicIssue is NOT NULL) AND (dtMicIssue  <> '1900-01-01 00:00:00') 
 THEN CONVERT(SMALLDATETIME,dtMicIssue)  
     ELSE NULL END AS DATE


INTO    #LTS_MAP
FROM    SBAURSQL001.LTSArchive.dbo.LoanMaster_0609
Ian Jacobs
Ah I see, one other question can I omit the initial field dtMicIssue and only output the MIP_CERTIFICATION_DATE?
JMS49
Yeah I believe you can.
Ian Jacobs
Got it, Thanks to all for their kind assistance!
JMS49
+2  A: 

Since you are doing a SELECT INTO, SQL Server needs to know a name for every column. Your second column (the one with the CASE) does not have an explicit name. Decide what you want to call it, then put

AS ColumnName

immediately after the END that ends the CASE

AakashM
+2  A: 

Try this

SELECT dtMicIssue as LATE_CHARGE_FACTOR,
   CASE WHEN (dtMicIssue is NOT NULL) AND 
          (dtMicIssue <> '1900-01-01 00:00:00') 
        THEN CONVERT(SMALLDATETIME,dtMicIssue)
        ELSE NULL END As SomeColumnName

INTO #LTS_MAP 
FROM SBAURSQL001.LTSArchive.dbo.LoanMaster_0609
Charles Bretana