sql server - How can I set a start and modified date with one SQL Update command? -
i have simple sql server table:
create table [dbo].[usertest] ( [usertestid] int identity (1, 1) not null, [userid] int not null, [modifieddate] datetime null, [starteddate] datetime null );
i set modified date this:
update usertest set modifieddate = @modifieddate usertestid = @usertestid , userid = @userid
but there way can set starteddate
in same sql @modifieddate
if starteddate
null
?
you can use coalesce statement set starteddate if not null, or @modifieddate if is.
update usertest set modifieddate = @modifieddate, starteddate = coalesce(starteddate, @modifieddate) usertestid = @usertestid , userid = @userid
Comments
Post a Comment