SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 QueryHelp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

keka3309
Starting Member

11 Posts

Posted - 03/17/2013 :  09:41:45  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3559 Posts

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

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/17/2013 :  13:30:59  Show Profile  Reply with Quote

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


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000