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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 QueryHelp

Author  Topic 

keka3309
Starting Member

11 Posts

Posted - 2013-03-17 : 09:41:45
Hi,

can anyone help me to write a query for the below data

A B C D E F G
1 100 1 NULL D 1001 2013-03-15
2 100 1 NULL N 1001 2013-03-15
3 100 1 2013-03-15 A 1001 2013-03-15
4 100 2 NULL D 1002 2013-03-17
5 100 2 NULL N 1002 2013-03-17
6 100 2 2013-03-17 A 1002 2013-03-17


A,B,C,D,E,F are the columns which i have in my table and i have to derive the column G.

Whenever the column C is same( like 1) then the date from column D for type A in column E should replace the Null values for type D and N.

please let me know if any questions

Thanks for your help in advance

Keka

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-17 : 10:48:52
What would be the expected output for the sample data you posted?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-17 : 13:30:59
[code]
SELECT A,B,C,D,
E,F,
COALESCE(D,MAX(CASE WHEN E='A' THEN D END) OVER (PARTITION BY B,C)) AS G
FROM Table t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -