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 |
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2008-03-16 : 15:19:03
|
| I have the following tableCall_ID Order_ID Activity LastUpdateDate 1 100 'Install' 01/01/20072 100 'Add' 01/02/20073 101 'Install' 02/02/20074 105 'Install' 03/05/20075 105 'Other' 03/05/20076 106 'NEW' 04/05/20077 106 'Charge' 04/06/2007 For all orders which has install as an activity, and lastupdate is equl or more than 01/01/2007 find where there is an 'add' activity for that order or no add activityI want to display results like this Order_ID Activity Result100 Install Add 101 Install No add activity 105 Install No add activity |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-03-17 : 00:44:19
|
| Hi,you want like this Declare @Table Table (Call_ID INT, Order_ID INT, Activity VARCHAR(100), LastUpdateDate DATETIME)INSERT INTO @TABLESELECT 1 ,100 ,'Install', '01/01/2007' UNION ALLSELECT 2 ,100 ,'Add', '01/02/2007 ' UNION ALLSELECT 3 ,101 ,'Install', '02/02/2007 ' UNION ALLSELECT 4 ,105 ,'Install', '03/05/2007' UNION ALLSELECT 5 ,105 ,'Other', '03/05/2007' UNION ALLSELECT 6 ,106 ,'NEW', '04/05/2007' UNION ALLSELECT 7 ,106 ,'Charge' ,'04/06/2007'--SELECT * FROM @TABLESELECT Order_ID, Activity , CASE WHEN Activity = 'Install' THEN 'Add' ELSE 'No add activity' END AS ResultFROM @TABLE WHERE Activity = 'Install' and LastUpdateDate >= '01/01/2007' |
 |
|
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2008-03-17 : 09:44:56
|
| Rangnath, your query is not *giving* result I wantHere is my version of query but it displays result like thisOrder_id activity result100 Install NULL100 Install ADD Query should tell us whether for install there is an add acitivity or notorder_id activity result100 Install ADD 105 Install No AddSELECT distinct t.order_id, t.activity, CASE dd.activity WHEN 'ADD SERIAL #' THEN 'ADD SERIAL #' END FROM(SELECT distinct order_id,activityFROM demand_done WHERE LastUpdateDT >= '01/01/2007' and activity= 'install' ) AS T LEFT JOIN demand_done dd on t.order_id = dd.order_id |
 |
|
|
cshah1
Constraint Violating Yak Guru
347 Posts |
Posted - 2008-03-17 : 10:08:25
|
| I found the query I need sorry sometime I go nuts.. just need a cup of coffee |
 |
|
|
|
|
|
|
|