gpt4 book ai didi

tsql - 多参数 IF 语句 - T-SQL

转载 作者:行者123 更新时间:2023-12-03 10:22:51 25 4
gpt4 key购买 nike

如何在 T-SQL 中编写具有多个参数的 IF 语句?

当前源错误:

DECLARE @StartDate AS DATETIME
DECLARE @EndDate AS DATETIME

SET @StartDate = NULL
SET @EndDate = NULL

IF (@StartDate IS NOT NULL AND @EndDate IS NOT NULL)
BEGIN
-- do some work
END

它抛出以下错误:

Incorrect syntax near the keyword 'AND'. Incorrect syntax near the keyword 'AND'. Incorrect syntax near ')'.

最佳答案

你做得对。空代码块是导致您的问题的原因。这不是条件结构:)

DECLARE @StartDate AS DATETIME

DECLARE @EndDate AS DATETIME

SET @StartDate = NULL
SET @EndDate = NULL

IF (@StartDate IS NOT NULL AND @EndDate IS NOT NULL)
BEGIN
print 'yoyoyo'
END

IF (@StartDate IS NULL AND @EndDate IS NULL AND 1=1 AND 2=2)
BEGIN
print 'Oh hey there'
END

关于tsql - 多参数 IF 语句 - T-SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1971263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com