2

I am using SQL Server 2008 Enterprise. I want to export the query result into csv file from SQL Server Management Studio. The issue is, the default csv file is comma (',') separated for each result column in each exported row, and I want to make it '\t' separated since comma exists in some of the result column values.

Any quick solutions?

thanks in advance, George

3 Answers 3

5

If you really want the \t delimiter write a query like this

select 
  Cast(PersonCode as varchar(50)) + '\t'
  + Cast(PersonReference as varchar(50))    
from People

The casts are just incase you aren't working with varchar types, but you don't need them if you are. Run this query with results to text and just paste the result into notepad or similar.

Sign up to request clarification or add additional context in comments.

17 Comments

You don't even need to paste. Using results to grid, just right click and save results as, using all files as the file type, to allow you to save as a txt file or whatever you want.
@ Mark Dickinson: isn't that what I said in my answer?! :)
Not working for me since I have binary type if case is not used. Here is the error message. My further question, if I cast binary to varchar, then cast back, is it ensured that originial value of binary is restored? Msg 402, Level 16, State 1, Line 1 The data types nvarchar and varbinary(max) are incompatible in the add operator.
@Mitch: I don't have that option in my save results as. I just get Export File (csv), or All files (.). Maybe I misunderstand the '\t' in the question, does that mean tab? Anyway my example means you could use War and Peace for a delimiter if you want so I still think its good :)
@Mitch, I'm on 2005 in the office, that might explain the difference.
|
5

When you click "Save as" and you are prompted to enter a filename, drop down the box below the filename and select "Text (Tab delimited)"

1 Comment

Thanks, it works in SQL Server 2008, and I have tried in SQL Server 2005 no such feature?
-1

It saves only the 1st record as Tab delimited. I can't figur eout, how it will select all rows from query analyzer results section.

1 Comment

When you save the results set that way, it only saves the selected rows. Right-click, select all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.