Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
savolol
Starting Member
2 Posts |
Posted - 2011-06-17 : 08:16:44
|
| How can I express this in SQL Server?Select distinct xxx,ZZZ,max(decode(COLUMN,'A','VALUEFROMCOLUM2',null)) as "A",max(decode(COLUMN,'B','VALUEFROMCOLUM2',null)) as "D"FROM TABLE -- COLUMN has values A and B and I want those in different colums at the resultGroup by xxx,ZZZorder by zzz |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-06-17 : 08:32:25
|
| max(case when column = 'A' then 'VALUEFROMCOLUM2' end) as [A]==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
jcelko
Esteemed SQL Purist
547 Posts |
Posted - 2011-06-17 : 13:38:04
|
| Use the CASE expression. Oracle also has the CASE expression and you should be replacing the old DECODE() with it in your old code.--CELKO--Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQLData and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL |
 |
|
|
|
|
|