Bobson
Bobson

Reputation: 233

Adding columns to the table

What i have right now is a stored procedure which have a sql statement that produces the result below.

| Name | Lastname | Age | Gender | <- Columns
|Robert|   Bob    | 30  |  Male  | <- Row1

What i am trying to do from here is to get the columns and place them on the first row. For example

| Name | Lastname | Age | Gender | <- Columns
| Name | Lastname | Age | Gender | <- Row1
|Robert|   Bob    | 30  |  Male  | <- Row2

How can i accomplish this? All help is appreciated!

Upvotes: 0

Views: 75

Answers (1)

Dave Zych
Dave Zych

Reputation: 21887

The easiest way is probably just to UNION it...

SELECT
   'LastName',
   'FirstName',
   'Age',
   'Gender'
UNION ALL
SELECT
   LastName,
   FirstName,
   Age,
   Gender
FROM YourTable

Note that the columns specified in the second select all have to be nvarchar in this case otherwise you'll probably get a conversion error.

Upvotes: 1

Related Questions