Ahmad
Ahmad

Reputation: 15

MSSQL Query - database

I need help in a query to get me result as below based on this table.

Table
ID   Date Value
---  ---- -----
1    jan1  Hello
2    Jan2  Sample

Query Result:

ID   Date Value  Info
---  ---- -----  -----
1    jan1  Hello  A
1    jan1  Hello  B
2    Jan2  Sample A
2    Jan2  Sample B

Can any help me please?

Upvotes: 0

Views: 31

Answers (2)

liquidacid
liquidacid

Reputation: 118

If you are wanting the info column to be based on the values of another column, use case.

MSDN case documentation

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521053

You can use a UNION here, with a computed column for Info:

SELECT ID, Date, Value, 'A' AS Info
FROM yourTable
UNION ALL
SELECT ID, Date, Value, 'B'
FROM yourTable

Upvotes: 1

Related Questions