![]() ![]() if no schemaname provided, default to dbo PRINT('NO TABLE NAME SUPPLIED, UNABLE TO CONTINUE')ĭECLARE VARCHAR(MAX), VARCHAR(MAX), VARCHAR(MAX), int Here is the script: IF OBJECT_ID('get_csvFormat', 'P') IS NOT NULLĬREATE PROCEDURE VARCHAR(20), char(1)) I've made numerous fixes/changes to the original script, but the bones of it are from the OP, whoever that was. This STP (Which for the most part I take no credit for, and I can't find the site I found it on), takes a schema name, table name, and Y or N as input parameters and queries the supplied table, outputting each row in comma-separated, quoted, csv format. In an attempt to track down where I found the script to post an update, I came across this thread and it seemed like a good spot to share it. You can use any programming language or a batch file to automate thisĭead horse perhaps, but a while back I was trying to do the same and came across a script to create a STP that tried to do what I was looking for, but it had a few quirks that needed some attention.As per when using SQLCMD, you can run stored procedures instead of the actual queries.It is important to quote the comma separator as -t',' vs just -t, You can use any programming language or even a batch file to automate thisĮxample: bcp "SELECT * FROM " queryout C:\Test.csv -c -t',' -T -S. You may run a stored procedure instead of the actual query (e.g. This approach will have the "Rows affected" information in the bottom of the file, but you can get rid of this by using the "SET NOCOUNT ON" in the query itself. d DatabaseName -E -s, -W -Q "SELECT * FROM TableName" > C:\Test.csvĭo not quote separator use just -s, and not quotes -s',' unless you want to set quote as separator. Paste the copied content on Microsoft Excelįrom the command prompt, you can run the query and export it to a file: sqlcmd -S. ![]() Click on the top-left corner to select all rowsĤ. Run a SELECT statement to filter your dataĢ. Some ideas: From SQL Server Management Studio 1. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |