thormayer
thormayer

Reputation: 1070

SQL Server isnull is not working with another expression?

I'm trying to make an expression in SQL Server, that will check if certain column is null, and if it is null, set a new GUID number..

This is my code :

select 
    isnull((select Guid 
            from therapists 
            where username = 'ido' and password = 'ido'), 
           (update therapists 
            set guid = NEWID() 
            where username = 'ido' and password = 'ido'))

Upvotes: 0

Views: 41

Answers (1)

dario
dario

Reputation: 5269

You can try this:

UPDATE therapists SET guid = NEWID() 
WHERE username = 'ido' 
  AND password = 'ido'
  AND guid IS NULL;

Upvotes: 1

Related Questions