SQL server t-sql help please

Archived from the original Sajha.com — preserved as posted, replies can no longer be added here.
Start a New Discussion
Archived Post

Hi, I am new to T-SQL and looking for some help on a t-sql. your help is very much appreciated. i want my update to update table1 accoirding this View (see attatched pic, name it thisView). table1 has the primary key of New_battelleId. I want my update to be something like this.. update table1 set new_batChase1Req1Mailed(**condition described below)=getDate() where new_battelleId=thisView.new_battelleId There are more columns to this view, only few are shown here: new_batChase1Req1Mailed,new_batChase1Req2Mailed,new_batChase1Req3Mailed, new_batChase2Req1Mailed,new_batChase2Req2Mailed,new_batChase1Req1Mailed, new_batChase3Req1Mailed,new_batChase3Req2Mailed,new_batChase3Req1Mailed notice how each 'Chase' has 3 'Req' each. condition to update** So basicly, If the chase is 1 in thisView, I want to update table1's new_batChase1Req1Mailed or new_batChase1Req2Mailed or new_batChase1Req3Mailed. The alrogorithm is if all three requests are null, put date into req1. if there is date in req1, the update req2(req3 will be null). If both req1 and req2 have dates then  update req3 with the date. you get the picture. I want similar thing to happen for req1,req2 and req3 for chase2 and chase3 also, depending on the chase value from thisView. thanks for help. Last edited: 29-Aug-10 10:56 PM Last edited: 29-Aug-10 10:56 PM Last edited: 29-Aug-10 10:58 PM

the_hareeb · Aug 29, 2010 10:55 PM · 10,281 views

2 Replies

Update Table1 Set new_batChase1Req1Mailed = Case When Coalesce(new_batChase1Req1Mailed,new_batChase1Req2Mailed,new_batChase1Req2Mailed) is null then getdate() Else null End, new_batChase1Req2Mailed  = Case When new_batChase1Req1Mailed is not null then getdate() Else null End, new_batChase1Req3Mailed  = Case When Coalesce(new_batChase1Req1Mailed,new_batChase1Req2Mailed) is null then getdate() Else null End where new_battelleId = thisView.new_battelleId

secretkiller · Aug 30, 2010 6:35 AM

thanks, I didnt know about colease. lemme try that. 

the_hareeb · Aug 30, 2010 7:58 AM

This conversation is preserved exactly as it was on the original Sajha.com and can't accept new replies.

Start a New Discussion

You might be interested in...

Recent Classifieds View all
Upcoming Events View all
Service Providers View all