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 |
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-01 : 07:12:46
|
how i merge select and update queryfirst i want to select data and then i want to update that data this is my select query SELECT CalDate,[Timein],[Timeout],CONVERT(varchar(8),DATEADD(ss,DATEDIFF(ss,[Timein],[Timeout]),0),108) AS SpendTimeFROM attendancethis is my update queryupdate attendance setexcessshort = CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) / 60 as varchar ) + ':' + CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) % 60 as varchar ) from attendance how i merge that queryimmad uddin ahmed |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-06-01 : 09:19:39
|
quote: Originally posted by immad how i merge select and update queryfirst i want to select data and then i want to update that data this is my select query SELECT CalDate,[Timein],[Timeout],CONVERT(varchar(8),DATEADD(ss,DATEDIFF(ss,[Timein],[Timeout]),0),108) AS SpendTimeFROM attendancethis is my update queryupdate attendance setexcessshort = CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) / 60 as varchar ) + ':' + CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) % 60 as varchar ) from attendance how i merge that queryimmad uddin ahmed
You can use OUTPUT clause as shown below if you are on SQL 2005 or laterupdate attendance setexcessshort = CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) / 60 as varchar ) + ':' + CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) % 60 as varchar )output INSERTED.CalDate,INSERTED.[Timein],INSERTED.[Timeout],CONVERT(varchar(8),DATEADD(ss,DATEDIFF(ss,INSERTED.[Timein],INSERTED.[Timeout]),0),108) BTW, you can simply subtract one time from the other to do the conversion - CONVERT(varchar(8),INSERTED.[Timein]-INSERTED.[Timeout],108) |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-06-03 : 03:15:53
|
>> first i want to select data and then i want to update that data I think you need old data before UPDATE....So you can use DELETED virtual table to display OLD DATA before UPDATEupdate attendance setexcessshort = CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) / 60 as varchar ) + ':' + CAST ( ABS(600 - DATEDIFF (MINUTE, Timein, timeout ) ) % 60 as varchar )output DELETED.CalDate, DELETED.[Timein],DELETED.[Timeout], CONVERT(varchar(8),DELETED.[Timein]-DELETED.[Timeout],108)--Chandu |
 |
|
immad
Posting Yak Master
230 Posts |
Posted - 2013-06-03 : 03:36:44
|
Thank for the helpimmad uddin ahmed |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-03 : 03:53:33
|
whats the datatype of excessshort?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-06-04 : 00:42:32
|
quote: Originally posted by immad Thank for the helpimmad uddin ahmed
Welcome --Chandu |
 |
|
|
|
|
|
|