Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a flat file from sql table

Status
Not open for further replies.

bunmiA

MIS
Apr 20, 2004
27
GB
How do you create acomma delimited flat file from a sql table. I know how to do it using a print statement withing a cursor. but I would like to do it using a select staement only. (and not the cursor.) any ideas???
 
Code:
SELECT '"' + isNull(textField1,'') + '",' 
+ isNull(convert(varchar(10), intField),0) + ','
+ isNull(convert(varchar(10), dateField,1),'""')
FROM myTable


Note that you want isNull() statements or a whole row will be lost if any one value is null.
Also, all non-text data will need to be converted to text since you are outputing a text string.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top