Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2008-05-21 : 11:54:19
|
Hi,The statement below works great; it makes the Excel sheet and inserts the data. NO Problem. However, I need it to do it with column headers and I can not seem to get that to work. I tried aliases, but nothing that I did worked. If anyone ahs any ideas I would really appreciate it. Thank youhere is my codeinsert temptransD (PlID, ETYPE, ETDATE, PLAN_ID, HID, ENR_ID, Creat_Type, Creation_Date, Source, Cur_State)Select #transfm.[PlID], #transfm.[ETYPE], #transfm.[ETDATE], #transfm.[PLAN_ID], #transfm.[HID], #transfm.[ENR_ID], #transfm.[Creat_Type], #transfm.[Creation_Date], #transfm.[Source], cast(#transfm.[Cur_State] as varchar(10)) as 'Cur_State'From #transfm Exec Master..xp_cmdshell 'bcp " Select * from sdoh_rec_Work.dbo.temptransD" queryout "\\Bmtsn09\Arc\Transact_Adv.xls" -c'ITM |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-21 : 12:13:52
|
try using this approach:-http://weblogs.sqlteam.com/brettk/archive/2005/04/13/4395.aspx |
 |
|
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2008-05-21 : 12:20:30
|
Thanks but I do not want to change this whole thing to to another method just ot get headers in it. I had them before and some how lost it but it was realy simple; I just cannot remeber what I had to do. Thank youITM |
 |
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2008-05-21 : 17:48:38
|
did you tryinsert temptransD(PlID, ETYPE, ETDATE, PLAN_ID,HID, ENR_ID, Creat_Type, Creation_Date,Source, Cur_State)Select 'PlID' as 'PlID', 'ETYPE' as 'ETYPE', 'ETDATE' as 'ETDATE', 'PLAN_ID' as 'PLAN_ID','HID' as 'HID', 'ENR_ID' as 'ENR_ID', 'Creat_Type' as 'Creat_Type', 'Creation_Date' as 'Creation_Date','Source' as 'Source', 'Cur_State' as 'Cur_State'unionSelect #transfm.[PlID], #transfm.[ETYPE], #transfm.[ETDATE], #transfm.[PLAN_ID],#transfm.[HID], #transfm.[ENR_ID], #transfm.[Creat_Type], #transfm.[Creation_Date],#transfm.[Source], cast(#transfm.[Cur_State] as varchar(10)) as 'Cur_State'From #transfm???An infinite universe is the ultimate cartesian product. |
 |
|
itmasterw
Yak Posting Veteran
90 Posts |
Posted - 2008-05-22 : 08:49:34
|
Thank you that worked.ITM |
 |
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2008-05-22 : 15:02:05
|
Just make sure to add a sort column so your header doesn't end up mixed in the data.An infinite universe is the ultimate cartesian product. |
 |
|
|
|
|
|
|