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

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -