Groups | Blog | Home
all groups > sql server dts > december 2005 >

sql server dts : Export from table to multiline text file


kapsolas
12/28/2005 8:39:03 AM
I am not sure if this is possible or not but I am trying to do the following.
I need to export data to a test file in the following format:

[Users]
firstname=john
lastname=smith

when Creating my table which stores this information, I am using T-SQL to
concatenate my values into one row, the row looks as follows
ROW1 => [Users] firstname=john lastname=smith
ROW2 => [Users] firstname=jane lastname=smith
....
ROWN => [Users] firstname=user_N lastname = user_N


is there a quick way to get this information out of each row and onto a new
line when exporting to a text file?

I'm really not sure at all how to approach this so any ideas would be
greatly appreciated.

Ed Enstrom
12/28/2005 5:54:35 PM
[quoted text, click to view]

Try this:

select substring(ColumnName, CHARINDEX('firstname',ColumnName), CHARINDEX('lastname',ColumnName) -
CHARINDEX('firstname',ColumnName)-1) + char(13) + char(10) + substring(ColumnName, CHARINDEX('lastname',ColumnName),
len(ColumnName) - CHARINDEX('lastname',ColumnName) +1)
kapsolas
12/29/2005 6:26:02 AM
Ed Enstrom,

Thank!! just adding the '\r\n' as char characters did the trick.
Just had to add those in where I was building my string with out having do
to any substrings :)

SET @Users= '[USERS]' + char(13) + char(10)
+ 'First_Name=' + @FName + char(13) + char(10)
+ 'Last_Name=' + @LName + char(13) + char(10)

Nice to know you can add character values directly to a string, learn
something every day.

kapsolas


[quoted text, click to view]
AddThis Social Bookmark Button