Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 stored procedure output

Author  Topic 

bmmpam
Starting Member

5 Posts

Posted - 2007-02-08 : 10:05:14
I am using a stored procedure to query tables and format a record to write to a file. Below is the syntax I'm using to do the write.

set @cmd = 'echo ' + rtrim(@patient_rec) + ' >> f:\output\recall.csv'
exec master..xp_cmdshell @cmd

The procedure will write about 30,000 records or so and then quit writing to the file. Is there a setting I have to modify to write more records or is there a better way to do this?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-08 : 10:09:09
Why don't you use BCP and output all the record at once?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bmmpam
Starting Member

5 Posts

Posted - 2007-02-08 : 10:11:46
Pretty new to sql server and am not sure how to do this. Would I write all records to a temp table and then use BCP?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-08 : 10:16:10
No, you can output the result of a query too, to a file directly.

declare @sqlcmd varchar(8000)

set @sqlcmd = 'bcp "SELECT FirstName, LastName FROM AdventureWorks.Person.Contact ORDER BY LastName, Firstname" queryout X:\Contacts.txt -c -T'

exec master..xp_cmdshell @sqlcmd

FOr more information about BCP command, turn to Books Online and do a search for BCP


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

bmmpam
Starting Member

5 Posts

Posted - 2007-02-09 : 10:27:55
Peso, Thanks for your help, but I am using a quite lengthy stored procedure to gather my data so it doesn't seem like bcp is the best approach. Any other suggestions?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-02-09 : 10:31:23
Sure put the sproc output into a table and bcp out that table



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

bmmpam
Starting Member

5 Posts

Posted - 2007-02-09 : 11:17:30
I can give this a try. Any idea why it stopped after writing 30,000+ records?
Go to Top of Page
   

- Advertisement -