dimanche 26 avril 2015

How can I set a start and modified date with one SQL Update command?

I have a 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 the modified date like this:

UPDATE UserTest
SET    ModifiedDate = @ModifiedDate
WHERE  UserTestId = @UserTestId
AND    UserId = @UserId

But is there a way I can also set the StartedDate in the same SQL to the @ModifiedDate if the StartedDate is NULL ?

Aucun commentaire:

Enregistrer un commentaire