Solved

T-SQL to CSV file

Posted on 2014-02-20
3
475 Views
Last Modified: 2014-02-21
I have the following stored procedure I'm running but it only outputs on records.  When I manually execute " exec Ntier_DesertOrtho.dbo.CreateAppointmentFile " I get all the records I'm expecting to get 100+ ,  but when I manually execute the entire below I get an output of 0 reported but the file is actually created with 1 record in it.

THank you for your help ....


DECLARE @sql varchar(8000)
SELECT @sql = 'bcp "exec Ntier_DesertOrtho.dbo.CreateAppointmentFile" '
+ 'queryout e:\bmc\extract\DOAppointments.csv -c -t^| -T -S'
+ @@servername
EXEC master..xp_cmdshell @sql
0
Comment
Question by:jtbrown1111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
x-men earned 400 total points
ID: 39876341
Use the SQL Server Import / Export wizard to get the data to the csv. Save the package for later execution.
0
 
LVL 27

Assisted Solution

by:Zberteoc
Zberteoc earned 100 total points
ID: 39876495
What is t^|? If the separator is | you should have t|. If you use both characters wrap them in quotes: t"^|"
0
 

Author Comment

by:jtbrown1111
ID: 39878530
What I ended up doing which worked really well was to use the Import/Export Wizard, created a package using a query then created an SQL Agent job to run it nightly.

Thanks everyone for your help ...
0

Featured Post

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question