1

When I give this query:
select 'a', 'b'

I get the output:

-------------------------------------
|(No column name) | (No column name)|
-------------------------------------
|       a         |        b        |
-------------------------------------

But I want the results(a and b) to be in separate rows.

Could someone please explain me or give sample query to attain this?

albin
  • 194
  • 3
  • 13

2 Answers2

2

Need to change your query to use union.

Query:

 select 'a'
 union all
 select 'b'
Vasanth
  • 1,670
  • 1
  • 13
  • 17
  • Is this the only possible way? Creating as many select statements as the number of values I have? – albin Jul 12 '13 at 01:40
  • No, you can do it in different values. is your values coming from a table or how its defined? – Vasanth Jul 12 '13 at 01:42
  • I get the values from an external file. – albin Jul 12 '13 at 11:16
  • You can pass the values from external file as some delimited text example: comma and use the logic mentioned in this post to split it as rows: http://stackoverflow.com/questions/5722700/how-do-i-split-a-delimited-string-in-sql-server-without-creating-a-function – Vasanth Jul 12 '13 at 13:48
1

Since your are using MS SQL Server you can use UNPIVOT operator to do what you want,

Have a look at this article : http://tuvianblog.com/2012/07/12/how-to-unpivot-table-in-sql-server-unpivot-table-example-in-sql-server/

Thanu
  • 2,481
  • 8
  • 34
  • 53