x

Select and set in column

I got a simple select case with where condition, where Conditions are different values.
How Can I put those condition values into columns.
For exemple:

select fld1, fld, fld3 from tbl where val in (13, 14, 17)

I want to display those data in table configured like:

 fld1| fld2|fld3| 13| 14| 17|
 12    12   23   val val val
more ▼

asked Jun 09, 2011 at 07:55 AM in Default

avatar image

Gogolo
323 24 26 31

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Would this do it or have I completely missed the point.

    SELECT
           fld1, fld2, fld3,
           CASE WHEN val = 13 THEN val ELSE 0 END AS [13],
           CASE WHEN val = 14 THEN val ELSE 0 END AS [14],
           CASE WHEN val = 17 THEN val ELSE 0 END AS [17]
          
           
           FROM #Temp AS T
more ▼

answered Jun 09, 2011 at 08:08 AM

avatar image

Mrs_Fatherjack
5.1k 64 66 76

Works good... Thank you

Jun 09, 2011 at 11:22 PM Gogolo
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x149

asked: Jun 09, 2011 at 07:55 AM

Seen: 845 times

Last Updated: Jun 09, 2011 at 08:01 AM

Copyright 2016 Redgate Software. Privacy Policy