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 |
keka3309
Starting Member
11 Posts |
Posted - 2013-03-17 : 09:41:45
|
Hi,can anyone help me to write a query for the below dataA B C D E F G 1 100 1 NULL D 1001 2013-03-15 2 100 1 NULL N 1001 2013-03-153 100 1 2013-03-15 A 1001 2013-03-154 100 2 NULL D 1002 2013-03-175 100 2 NULL N 1002 2013-03-176 100 2 2013-03-17 A 1002 2013-03-17A,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 questionsThanks for your help in advanceKeka |
|
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? |
|
|
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 GFROM Table t[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|
|
|