sql - Transact-sql 中的条件运算符

标签 sql sql-server

有没有办法缩短这个时间,例如在 Transact-sql 中使用某种条件运算符?

IF @ParentBinaryAssetStructureId = -1
BEGIN
    SET @ParentBinaryAssetStructureId = NULL
END

UPDATE  BinaryAssets.BinaryAssetStructures 
SET     ParentBinaryAssetStructureId = @ParentBinaryAssetStructureId
WHERE   BinaryAssetStructureId = @OriginalBinaryAssetStructureId

最佳答案

使用NULLIF()

UPDATE  BinaryAssets.BinaryAssetStructures 
SET     ParentBinaryAssetStructureId = NULLIF(@ParentBinaryAssetStructureId,-1)
WHERE   BinaryAssetStructureId = @OriginalBinaryAssetStructureId

关于sql - Transact-sql 中的条件运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2088977/

相关文章:

mysql - 选择字符串直到字符串中的第一个或第二个空格

mysql - 在 MySQL 中使用数字行 ID 有什么优点?

sql - 如何在 java/jsp 中执行 MS SQL Server 存储过程并返回表数据?

sql - 设置用户表时有什么好的做法?查看一些新手教程,但不确定如何正确执行 "really"

sql-server - 如何在 JDBC Spring 配置中指定 SQL Server 的架构

sql-server - 连接断开时干净地关闭 SQL 连接

sql-server - dbGo 或 dbExpress for Delphi 2010 与 Microsoft SQL Server

来自两个连接查询的 MySQL "Group By"

c# - Dapper:是否可以自定义特定类型的特定字段的类型映射?

sql - 如何在 SQL Server 中获取明细表记录作为字符串