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 |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2010-09-17 : 16:49:32
|
| Hi EveryoneNeed help writing a query in sql Scenario:I have a table1 Name - RequestsTable 2 Name - ItemidRequestid is a primary key in the table 1 and foreign key in the table 2.Every request in table A is associated with 13 items in table B and each item id has completed date associated in table BI want see data asRequest Id Indicator134 Yes135 Nowhere indicator feild should check all the completed dates associated with each item for a request and give value = "no" if all the dates are equal to 1/1/1900 and yes if it is somethign other than 1/1/1900 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-18 : 09:18:33
|
| [code]SELECT a.RequestID, CASE WHEN b.Cnt > 0 THEN 'Yes' ELSE 'No' END AS IndicatorFROM TableA aINNER JOIN (SELECT RequestID, SUM(CASE WHEN Date <> '1900-01-01' THEN 1 ELSE 0 END) AS Cnt FROM TableB GROUP BY RequestID) bON b.RequestID = a.RequestID[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|