SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How can i create pipe delimited txt file from sql query results


How can i create pipe delimited txt file from sql query results

Author
Message
tswathi21
tswathi21
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 3
HI all,
pls can you answer me it's urgent task..i searched in online but no luck yet...
Lowell
Lowell
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91669 Visits: 41178

EXECUTE master.dbo.xp_cmdshell 'bcp "SELECT object_name(object_id) As TbLName,name as ColName FROM SandBox.sys.columns ORDER BY object_name(object_id), column_id" queryout C:\Data\Objects.txt -t"|" -c -T '



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
tswathi21
tswathi21
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 3
Hi Lowel,

Thanks for ur quick response ..can i do that in master database because i'm a tester i don't know ..can i do that or not..
Here is my database details..can you answer accordingly..

My db name:Max_Test
My table name: #temp.
I need these columns from that table are offer_id,reservation_num,personal_id,acct_nbr_he.
PLs reply TIA.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)

Group: General Forum Members
Points: 260693 Visits: 42163
tswathi21 (4/29/2012)
Hi Lowel,

Thanks for ur quick response ..can i do that in master database because i'm a tester i don't know ..can i do that or not..
Here is my database details..can you answer accordingly..

My db name:Max_Test
My table name: #temp.
I need these columns from that table are offer_id,reservation_num,personal_id,acct_nbr_he.
PLs reply TIA.



You want that with or without column headers?

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)

Group: General Forum Members
Points: 260693 Visits: 42163
Never mind. We'll do it both ways.

Since you're a tester and don't know much about SQL Server or SSMS, we'll do this as simply as possible.

Paste the following code into SSMS on same window that create the #Temp table, highlight the code, and then press the f5 key. Copy the output from the results and paste into notepad. Save the notepad file.

--===== Comment out from here through UNION ALL
-- if you don't want column headers.
SELECT 'Offer_ID' + '|'
+ 'Reserveration_Num' + '|'
+ 'Personal_ID' + '|'
+ 'Acct_Nbr_HE' + '|'
UNION ALL
SELECT CAST(Offer_ID) AS VARCHAR(8000)) + '|'
+ CAST(Reserveration_Num) AS VARCHAR(8000)) + '|'
+ CAST(Personal_ID) AS VARCHAR(8000)) + '|'
+ CAST(Acct_Nbr_HE) AS VARCHAR(8000)) + '|'
FROM temp
;




--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
tswathi21
tswathi21
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 3
Hello Jeff,

Thanks for ur time and quick response..
Actually I did in otherway ..
In SSMS- tools-options--there i select results to text ..and changed the custom delimited to | ..and i ran that it worked for me..Saved the results to a file....

Thank you so much again...
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search