dbTalk Databases Forums  

Export from table to multiline text file

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Export from table to multiline text file in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
kapsolas
 
Posts: n/a

Default Export from table to multiline text file - 12-28-2005 , 10:39 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.

Thanks.

Reply With Quote
  #2  
Old   
Ed Enstrom
 
Posts: n/a

Default Re: Export from table to multiline text file - 12-28-2005 , 04:54 PM






kapsolas wrote:
Quote:
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.

Thanks.
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)



Reply With Quote
  #3  
Old   
kapsolas
 
Posts: n/a

Default Re: Export from table to multiline text file - 12-29-2005 , 08:26 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


"Ed Enstrom" wrote:

Quote:
kapsolas wrote:
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.

Thanks.

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)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.