I am using SSIS 2008 R2 trying to add this script to my package. This is the source script for populating my table. I know my package works with a different source script. Does SSIS support temp tables? This script works perfectly in SSMS. How else can I do this? Like to have to use multiple data sources, one for each temp table in SSIS instead?
This is my SQL script that I added to the OLE DB Source editor in the Data Flow. Note that I currently just have a total of one Source connection and one source query in SSIS:
IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects o WHERE o.xtype IN ('U') AND o.id = object_id(N'tempdb..#GC_clientaddress')) DROP TABLE #GC_clientaddress; IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects o WHERE o.xtype IN ('U') AND o.id = object_id(N'tempdb..#client_demographics')) DROP TABLE #client_demographics; IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects o WHERE o.xtype IN ('U') AND o.id = object_id(N'tempdb..#max_dates')) DROP TABLE #max_dates; IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects o WHERE o.xtype IN ('U') AND o.id = object_id(N'tempdb..#max_dates2')) DROP TABLE #max_dates2; select distinct CONVERT(nvarchar(20),c.clientcode_c) AS client_id, --Legacy CDT# (must be the same legacy ID for all conversion tables) CONVERT(nvarchar(50),c.lastname_vc) AS last_name, CONVERT(nvarchar(50),c.firstname_vc) AS first_name, CONVERT(nvarchar(15),isnull(c.middlename_vc,'')) AS middle_name, CONVERT(nvarchar(20),c.altclientcode_vc) AS agency_id_no, --TNKIDS Number CONVERT(nvarchar(50), CASE WHEN c.gender_c = 'M' THEN 'Male' WHEN c.gender_c = 'F' THEN 'Female' WHEN c.gender_c = 'U' THEN 'Unknown' ELSE 'Unknown' END) AS gender, CONVERT(varchar(20), CASE WHEN c.gender_c = 'M' THEN 'M' WHEN c.gender_c = 'F' THEN 'F' WHEN c.gender_c = 'U' THEN 'U' Else 'U' END ) AS gender_code, CONVERT(nvarchar(9),(SUBSTRING(c.socialsecnum_c, 1,3)+SUBSTRING(c.socialsecnum_c, 5,2)+SUBSTRING(c.socialsecnum_c, 8,4))) AS ss_number, c.birthdate_d AS date_of_birth, --CONVERT(nvarchar(50), address1_vc) AS street_address_1, --CONVERT(nvarchar(50), address2_vc) AS street_address_2, --CONVERT(nvarchar(50), city_vc) AS City, --CONVERT(nvarchar(50), state_c) AS state, --CONVERT(nvarchar(2), state_c) AS state_code, --CONVERT(nvarchar(9), zip_c) AS zip_code, CONVERT(nvarchar(50), CASE WHEN c.religion_c = 'A' THEN '7th Day Adventist' WHEN c.religion_c = 'AG' THEN 'Agnostic' WHEN c.religion_c = 'AT' THEN 'Atheist' WHEN c.religion_c = 'B' THEN ' Buddhist' WHEN c.religion_c = 'BA' THEN 'Baptist' WHEN c.religion_c = 'C' THEN 'Catholic' WHEN c.religion_c = 'E' THEN 'Episopalian' WHEN c.religion_c = 'EC' THEN 'Ecumencial' WHEN c.religion_c = 'H' THEN 'Hindu' WHEN c.religion_c = 'HG' THEN 'Huguenot' WHEN c.religion_c = 'J' THEN 'Jewish' WHEN c.religion_c = 'JW' THEN 'Jehovahs Witness' WHEN c.religion_c = 'L' THEN 'Lutheran' WHEN c.religion_c = 'MU' THEN 'Muslim' WHEN c.religion_c = 'ME' THEN 'Methodist' WHEN c.religion_c = 'MEN' THEN 'Mennonite' WHEN c.religion_c = 'MO' THEN 'Mormon' WHEN c.religion_c = 'M' THEN 'Moslem' WHEN c.religion_c = 'N' THEN 'None' WHEN c.religion_c = 'NO' THEN 'Nondenominational' WHEN c.religion_c = 'O' THEN 'Other' WHEN c.religion_c = 'P' THEN 'Protestant' WHEN c.religion_c = 'PC' THEN 'Pentecostal' WHEN c.religion_c = 'PS' THEN 'Presbyterian' WHEN c.religion_c = 'Q' THEN 'Quaker' WHEN c.religion_c = 'UN' THEN 'Unknown' WHEN c.religion_c = 'UT' THEN 'Unitarian' ELSE 'Unknown' END) AS religion, UPPER(CONVERT(varchar(20), CASE -- Cased out religion codes KMH 06/17/10 WHEN c.religion_c = 'A' THEN 'A' WHEN c.religion_c = 'AG' THEN 'AG' WHEN c.religion_c = 'AT' THEN 'AT' WHEN c.religion_c = 'B' THEN ' B' WHEN c.religion_c = 'BA' THEN 'BA' WHEN c.religion_c = 'C' THEN 'C' WHEN c.religion_c = 'E' THEN 'E' WHEN c.religion_c = 'EC' THEN 'E' WHEN c.religion_c = 'H' THEN 'H' WHEN c.religion_c = 'HG' THEN 'HG' WHEN c.religion_c = 'J' THEN 'J' WHEN c.religion_c = 'JW' THEN 'JW' WHEN c.religion_c = 'L' THEN 'L' WHEN c.religion_c = 'MU' THEN 'MU' WHEN c.religion_c = 'ME' THEN 'ME' WHEN c.religion_c = 'MEN' THEN 'MEN' WHEN c.religion_c = 'MO' THEN 'MO' WHEN c.religion_c = 'M' THEN 'M' WHEN c.religion_c = 'N' THEN 'N' WHEN c.religion_c = 'NO' THEN 'NO' WHEN c.religion_c = 'O' THEN 'O' WHEN c.religion_c = 'P' THEN 'P' WHEN c.religion_c = 'PC' THEN 'PC' WHEN c.religion_c = 'PS' THEN 'PS' WHEN c.religion_c = 'Q' THEN 'Q' WHEN c.religion_c = 'UN' THEN 'UN' WHEN c.religion_c = 'UT' THEN 'UT' ELSE 'UN' END)) AS religion_code, CONVERT(nvarchar(50), --Added ethnicity case statement KMH 5/26/10 CASE WHEN c.race_c = 'H' THEN 'Hispanic' ELSE 'Non Hispanic' END) AS ethnicity, CONVERT(nvarchar(20), --Added ethnicity case statement KMH 5/26/10 CASE WHEN c.race_c = 'H' THEN '01' ELSE '02' END) AS ethnicity_code, CONVERT(nvarchar(50), CASE WHEN c.race_c = 'A' THEN 'Asian' WHEN c.race_c = 'AI' THEN 'American Indian' WHEN c.race_c = 'B' THEN 'African American' WHEN c.race_c = 'BR' THEN 'Bi-racial' WHEN c.race_c = 'C' THEN 'Caucasian' WHEN c.race_c = 'H' THEN 'Hispanic' WHEN c.race_c = 'ME' THEN 'Middle Eastern' WHEN c.race_c = 'N' THEN 'Native Hawaiian/Other Pacific Islander' WHEN c.race_c = 'O' THEN 'Other' ELSE 'Other' END) AS race_1, UPPER(CONVERT(varchar(20), CASE WHEN c.race_c is NULL THEN 'U' WHEN c.race_c = 'A' THEN 'A' WHEN c.race_c = 'AI' THEN 'AI' WHEN c.race_c = 'B' THEN 'B' WHEN c.race_c = 'BR' THEN 'BR' WHEN c.race_c = 'C' THEN 'C' WHEN c.race_c = 'H' THEN 'H' WHEN c.race_c = 'ME' THEN 'ME' WHEN c.race_c = 'N' THEN 'N' WHEN c.race_c = 'O' THEN 'O' ELSE 'U' END))AS race_1_code, CONVERT(nvarchar(150), 'ar.client') AS original_table_name into #client_demographics from ar.client c INNER JOIN cd.enrollments en ON (c.uniqueid_c = en.clientid_c) INNER JOIN cd.episode ep ON (ep.uniqueid_c = en.episodeid_c and ep.clientid_c = c.uniqueid_c) where (ep.enddate_d is NULL OR ep.enddate_d >= getdate()-729) and en.location_c in (select code from dbo.yv_LKUP_OfficeLocation where state = 'TN')--change data pull with states here (check location codes on dbo.yv_LKUP_OfficeLocation) select distinct c.clientcode_c, c.firstname_vc, c.lastname_vc, ad.type_c, ad.startdate_d, ad.enddate_d, ad.address1_vc, ad.address2_vc, ad.city_vc, UPPER(ad.state_c) as state, ad.zip_c, ad.county_vc into #GC_clientaddress from echo.er_address ad LEFT JOIN ar.client c ON (ad.linkid_c = c.uniqueid_c) INNER JOIN cd.episode ep ON (ep.clientid_c = c.uniqueid_c) where c.clientcode_c in (select client_id from #client_demographics) select gc.clientcode_c, MAX(gc.startdate_d) AS maxdate into #max_dates from #GC_clientaddress gc where gc.clientcode_c in (select clientcode_c from #GC_clientaddress) AND(gc.enddate_d is NULL OR gc.enddate_d >= getdate()-730) group by gc.startdate_d, gc.clientcode_c --having count(*) > 2 select distinct clientcode_c, max(maxdate) maxdate into #max_dates2 from #max_dates group by clientcode_c order by clientcode_c select distinct cd.client_id, cd.last_name, cd.first_name, cd.middle_name, cd.agency_id_no, cd.gender, cd.gender_code, cd.ss_number, cd.date_of_birth, cd.religion, cd.religion_code, cd.ethnicity, cd.ethnicity_code, cd.race_1, cd.race_1_code, cd.original_table_name, gc.type_c, gc.startdate_d, gc.enddate_d, gc.address1_vc, gc.address2_vc, gc.city_vc, gc.[state], gc.zip_c, gc.county_vc from #client_demographics cd left join #GC_clientaddress gc on gc.clientcode_c = cd.client_id join #max_dates2 md on md.clientcode_c = gc.clientcode_c and md.maxdate = gc.startdate_d
This script works perfectly when run in SSMS, but fails with this error and no columns appear in the SSIS Editor interface.
Ryan D