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 |
|
headstrong
Starting Member
3 Posts |
Posted - 2006-01-12 : 14:26:07
|
| I was wondering if it's possible to create a stored Procedure, vbscript or in ASP to take the results of a query and export it to a text file on the SERVER, Fields need to be comma separated and all text fields need to be enclosed in "". also the filename.txt needs to be a variable so I can name it per query.SELECT name,uid,id,address FROM mytable,locationid WHERE id=12 "bob smith",234,12,"123 street ave, NC",222thanks for any help you can give me |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-01-12 : 15:00:09
|
| You can do this with DTS or bcp. DTS is available in Enterprise Manager. bcp is a command line executable. I prefer bcp.Tara Kizeraka tduggan |
 |
|
|
avmreddy17
Posting Yak Master
180 Posts |
Posted - 2006-01-12 : 16:31:10
|
| You can use do some thing like this...bcp pubs.dbo.authors out c:\temp\pubauthors.bcp -n -S CCSQL -U sa -P temp1234ThxVenu |
 |
|
|
headstrong
Starting Member
3 Posts |
Posted - 2006-01-12 : 16:49:35
|
| thanks for the repplayI tried the bcp and I got the CSV file but how would I add the "" to selective fields?for example around fields 1,4 below only and not the others."bob smith",234,12,"123 street ave, NC",222 |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-01-12 : 22:09:39
|
you can do it in your querySELECT '"'+ name + '"', uid, id, '"' + address + '"' FROM mytable,locationid WHERE id=12 -----------------'KH'if you can't beat them, have someone else to beat them |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-01-13 : 01:56:11
|
| That requires you to convert the columns to varchar if they are integer data typesMadhivananFailing to plan is Planning to fail |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-01-13 : 12:20:32
|
| Yes, but headstrong only needs to do it with text columns. Headstrong, you'll need to use the queryout option for bcp.exe to use khtan's solution.Tara Kizeraka tduggan |
 |
|
|
|
|
|
|
|