Ranjith S
Ranjith S

Reputation: 71

How to change result set view format in sql server

How to change My result set in sql server 2012

My Result set is

Name   Age   Gender
 X      21     M
 Y      21     F

I need this type of result

Name|Age|Gender
X|21|M
Y|21|f

Including column names

Upvotes: 5

Views: 21600

Answers (4)

Shammas
Shammas

Reputation: 461

I presume you are trying to change the result view in SQL Server Management Studio.

If this the case what you need is 'Result to Grid' option.

You need to go to:

Tools --> Options --> Query Results --> General --> and chnage Default Destination for results to 'Results to grids'

You can also use Ctrl + D to change the view to grid and 'Ctrl + T' to change it back to text.

or if you want to get the result with the pipe operator in between try the below query.

select name +'|'+age+'|'+gender from table

Upvotes: 5

DineshDB
DineshDB

Reputation: 6193

Press Ctrl+T to change to "Results from Text" (the button in SSMS is shown circled in red below):

enter image description here

Upvotes: 21

This will work for you:

select(convert(nvarchar(50),Name)+'|'+convert(nvarchar(50),Age)+'|'+convert(nvarchar(50),Gender)) 
[Name|Age|Gender]  from [Table_Name]

Upvotes: 0

arunb2w
arunb2w

Reputation: 1196

I think this will work

 select Convert(nvarchar(50),name)+'|'+Convert(nvarchar(50),age)+'|'+Convert(nvarchar(50),gender) as column from table_name

Upvotes: 1

Related Questions