Reputation: 71
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
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
Reputation: 6193
Press Ctrl+T to change to "Results from Text" (the button in SSMS is shown circled in red below):
Upvotes: 21
Reputation: 1
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
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