SQLTeam.com | Weblogs | Forums

Saving Query results


#1

while saving the query results into EXCL, some of the column results (as it is too big) does not fit into one column of the excl, while it creates an extra line, Is there any way to avoid this ?


#2

is it possible to save to csv first, then open up in excel?


#3

In SQL server , Result window , right click >> select save Result As

It will save your file in csv ,when you open it , your data is aligned.

Hope it helps !!


#4

Tried saving as txt file and csv file and I opened with EXCL , It does not align, The column having issue is VARCHAR(2000) and as soon as I open the saved file, it saves data in two rows.


#5

When you say the data goes to the second row, do you mean that it wraps around, or do you mean that data that you would expect to see in cell B2, for example, spills over into B2 and B3?

If the problem is wrap around, you can set the Excel cell properties to have no wrap-around.

If it is spilling over into the next row (as in B2 to B3), then something is not quite right. If you run the query and view the results in SSMS does it spill over into a new row?


#6

I doubt that it is a size problem, more likely the column has a Line Break embedded in the data (e.g. originally copy & paste from a document that contained a line break). If so this may solve it:

SELECT Col1, Col2,
       REPLACE(REPLACE(BigColumn, CHAR(13), ' '), CHAR(10), ' ') AS BigColumn
FROM YourTable
etc.

#7

I tried 'Wrap text' and it did not work,

Here is the example, It does not spilling over to the next row in SSMS. But while copying the result it does (Noticed that the text after the brackets goes to the next line . . and so the columns after that . .


#8

Thanks Kristen . .. . That worked .. . :smile: