Author |
Topic |
wbach3
Starting Member
3 Posts |
Posted - 2012-03-04 : 15:48:31
|
All I would like to run this code and return the results in excel using ssis. The only problem is I can only use temp tables. I am a wiz at dts however my new company only has ssis. I am a complete newb on it. Thank you.select Playerid,firstname+' '+lastname as Hostinto #afrom AbsUser ajoin playerhost b on a.userid = b.hostidwhere UserID in (31231,31238,31821,31806,31855,31828,31216,31893,31938,31802,31217,31218,31211,31818,31829,31826,31661,31945,31892,31862,31215,31820,31232,31237,31939,31213,31227,31228,31823,31942,31112,31659,31955,31655,30858,31663,31219,31822,31827,31150,31859,31776,31236,31235,31861,31860,31664,31662,31656,31863,31214,31658)--Max Playselect playerid, Max(AccountingDate)LastTripinto #sixfrom PlayerDaywhere ((slot_coinin >0) or (table_theowin <> 0) or (slot_jackpot <> 0)) and PlayerID in (select PlayerID from #a)group by playeridselect PlayerId,min(playernameid)playernameidinto #name1from PlayerNamewhere PlayerID in (select PlayerID from #a)group by playeridselect a.PlayerId, Firstname,Lastnameinto #name2from #name1 ajoin PlayerName b on a.playerid = b.PlayerID and a.playernameid = b.PlayerNameIDselect a.playerid,Firstname,Lastname,Host,LastTrip as LastTripDate, MonthInactive = datediff(mm,getdate(),LastTrip)*-1 into ##stagefrom #six ajoin #name2 b on a.playerid = B.playeridjoin #a c on a.playerid = c.playeridselect * from ##stagewhere lasttripdate <= GETDATE()-120order by host,monthinactive desc |
|
dataguru1971
Master Smack Fu Yak Hacker
1464 Posts |
Posted - 2012-03-05 : 14:22:46
|
Use Common Table Expressions. I imagine there could be more cleanup involved..but something like this would work as SQL Select for an SSIS dataflow.;WITH ctePlayerIDHost as ( SELECT Playerid,firstname+' '+lastname as Host FROM AbsUser a join playerhost b on a.userid = b.hostid where UserID in (31231, 31238,31821,31806,31855,31828,31216,31893,31938,31802,31217,31218,31211,31818,31829,31826,31661,31945,31892,31862,31215, 31820,31232,31237,31939,31213,31227,31228,31823,31942,31112,31659,31955,31655,30858,31663,31219,31822,31827,31150, 31859,31776,31236,31235,31861,31860,31664,31662,31656,31863,31214,31658)), cteLastTrip AS ( SELECT playerid, Max(AccountingDate)LastTrip FROM PlayerDay join ctePlayerID on PlayerDay.PlayerID = ctePlayerID WHERE ((slot_coinin >0) or (table_theowin <> 0) or (slot_jackpot <> 0)) group by playerid ), ctePlayerName1 AS ( SELECT PlayerId,min(playernameid)playernameid FROM PlayerName join ctePlayerID on PlayerName.PlayerID = ctePlayerID.PlayerID GROUP BY playerid ), ctePlayerName2 AS ( SELECT a.PlayerId, Firstname,Lastname FROM ctePlayerName1 a join PlayerName b ON a.playerid = b.PlayerID and a.playernameid = b.PlayerNameID ), cteStage AS ( SELECT a.playerid,Firstname,Lastname,Host,LastTrip as LastTripDate, MonthInactive = datediff(mm,getdate(),LastTrip)*-1 FROM cteLastTrip a join ctePlayerName2 b on a.playerid = B.playerid join ctePlayerIDHost c on a.playerid = c.playerid )SELECT a.playerid,Firstname,Lastname,Host,LastTripDate, MonthInactive FROM cteStageWHERE LastTripDate <= GETDATE()-120ORDER BY Host,MonthInactive Poor planning on your part does not constitute an emergency on my part. |
|
|
|
|
|