-
tsql - convert a vertical resulset to a horizontal resultset
here is my query:
select distinct SEC_RIGHT_ID from SEC_USER_RIGHT where USERID = 10
here is the resultset:
SEC_RIGHT_ID
------------
ABT_INQ
ABTENT_ADD
ABTENT_DEL
etc......
i need the resultset to be
10 ABT_INQ ABTENT_ADD ABTENT_DEL etc....
-
SQL Server provides a new statement called PIVOT for such transformation.
For earlier version you will have to write query with UNION, but if you do not know how many columns will be needed then it gets more complex as you need to generate the query dynamically.
-
Yes if you use sql2k5. For sql2k, check 'cross-tab report' in books online.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|