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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Oracle vs. SQL Server and Decode

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 result
Group by xxx,ZZZ
order 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.
Go to Top of Page

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 Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -