SQL Server isnull不能与另一个表达式一起使用?

时间:2015-05-03 08:28:23

标签: sql-server

我正在尝试在SQL Server中创建一个表达式,它将检查某个列是否为null,如果为null,则设置一个新的GUID号。

这是我的代码:

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

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

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