Save results from table
-
Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks
-
Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks
Do some research on CLR Stored procedure.
Parwej Ahamad R & D: REST services with WCF
-
Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks
If you're using SSMS to connect to your SQL Server express instance, hit Ctrl + Shift + F and execute your SP.
-
If you're using SSMS to connect to your SQL Server express instance, hit Ctrl + Shift + F and execute your SP.
Hi i have searched a lot and found that BCP can be used for this purpose. Now i have written a simple query Declare @str nvarchar(4000) set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T' Print(@str) Execute master..xp_cmdshell @str But i get the Output SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found. NULL SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti ons. NULL I have checked remote connections are enabled...... Looking forward for your reply. Thanks
-
Hi i have searched a lot and found that BCP can be used for this purpose. Now i have written a simple query Declare @str nvarchar(4000) set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T' Print(@str) Execute master..xp_cmdshell @str But i get the Output SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found. NULL SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti ons. NULL I have checked remote connections are enabled...... Looking forward for your reply. Thanks
Your BCP command must have the -S "Server Name" included, or else it'll search for the default instance.
set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -S InstanceName -T'
-
Hi i have searched a lot and found that BCP can be used for this purpose. Now i have written a simple query Declare @str nvarchar(4000) set @str='bcp "Select DISTINCT MAIN_ID from mydb.dbo.Postings " QUERYoUT "E:\Temp1.txt" -T' Print(@str) Execute master..xp_cmdshell @str But i get the Output SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]VIA Provider: The specified module could not be found. NULL SQLState = HYT00, NativeError = 0 Error = [Microsoft][SQL Native Client]Login timeout expired SQLState = 08001, NativeError = 126 Error = [Microsoft][SQL Native Client]An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connecti ons. NULL I have checked remote connections are enabled...... Looking forward for your reply. Thanks
I find this easier to bring the result set to the client as a datatable and then write out the table as a CSV file. BCP is fine for ETL processes but there are a number of issues around security (passwords in clear) and file system permissions.
Never underestimate the power of human stupidity RAH
-
Hi all I am working with SQL Server express edition. I want to save the results of my query in a text file. SELECT UserName,JoinDate,PostCount FROM Posts i have written this query in a SP. What i want is when i call the procedure the results should be saved in a text file. Thanks
Yes you can do it for sure... i have done this somany times Reffer here.. http://www.sqlteam.com/article/osql-storing-result-of-a-stored-procedure-in-a-file[^] Cheers,
ZAK