I have tried several times in several ways to use an Insert Into Statement which includes a CASE WHEN in a select statement to insert into the table. I have gotten errors that there weren't the same number of fields in the select as the insert. I tried altering it and can't seem to get it. Here is a clip of the statement without all the joins. Can someone enlighten me? Please?
Insert TCSFile (SASID, USID, Teacher_Last_Name, Teacher_First_Name, Teacher_Middle_Name, School_Code, LocalSectionID, LocalCourseID, LocalCourseName, Section_Entry_Date, Section_Exit_Date)
(SELECT DISTINCT
dbo.CSL_STD_DEMO_DISTRICT.STATE_NUMBER,
dbo.CSL_STAFF_DEMO_DISTRICT.LICENSE_NUMBER,
dbo.CSL_SMS_USER.LAST_NAME,
dbo.CSL_SMS_USER.FIRST_NAME,
dbo.CSL_SMS_USER.MIDDLE_NAME,
dbo.CSL_SET_SCHOOL_INFO.DISTRICT_NUMBER,
dbo.CSL_SMS_CLASS.CLASS_NUMBER,
dbo.CSL_SMS_DISTRICT_SUBJ_ITEM.NUMBER,
(convert(char(10),dbo.CSL_SMS_TERM_DATE.START_DATE,101)),
((Test=Case
when dbo.CSL_SMS_TERM_DATE.END_DATE >@end then null
when dbo.CSL_SMS_TERM_DATE.END_DATE <=@end then convert(char(10),dbo.CSL_SMS_TERM_DATE.END_DATE,101)
END ))
FROM
Insert TCSFile (SASID, USID, Teacher_Last_Name, Teacher_First_Name, Teacher_Middle_Name, School_Code, LocalSectionID, LocalCourseID, LocalCourseName, Section_Entry_Date, Section_Exit_Date)
(SELECT DISTINCT
dbo.CSL_STD_DEMO_DISTRICT.STATE_NUMBER,
dbo.CSL_STAFF_DEMO_DISTRICT.LICENSE_NUMBER,
dbo.CSL_SMS_USER.LAST_NAME,
dbo.CSL_SMS_USER.FIRST_NAME,
dbo.CSL_SMS_USER.MIDDLE_NAME,
dbo.CSL_SET_SCHOOL_INFO.DISTRICT_NUMBER,
dbo.CSL_SMS_CLASS.CLASS_NUMBER,
dbo.CSL_SMS_DISTRICT_SUBJ_ITEM.NUMBER,
(convert(char(10),dbo.CSL_SMS_TERM_DATE.START_DATE,101)),
((Test=Case
when dbo.CSL_SMS_TERM_DATE.END_DATE >@end then null
when dbo.CSL_SMS_TERM_DATE.END_DATE <=@end then convert(char(10),dbo.CSL_SMS_TERM_DATE.END_DATE,101)
END ))
FROM