Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 检查是否为工作日而非周末_Sql_Sql Server_Tsql_Case - Fatal编程技术网

Sql 检查是否为工作日而非周末

Sql 检查是否为工作日而非周末,sql,sql-server,tsql,case,Sql,Sql Server,Tsql,Case,我正在寻找: [Status.SchedFundingDate]在[今天]+[1个工作日]或之前 为此,我得到: convert(varchar(10), [Status.SchedFundingDate], 112) <= convert(varchar(10), getdate() + 1, 112) 我正在尝试解决的当前查询: [Status.SchedFundingDate]是否在[today]+[1个日历日]或之前 CASE WHEN UPPER(DATENAME(DW, ge

我正在寻找:

[Status.SchedFundingDate]在[今天]+[1个工作日]或之前

为此,我得到:

convert(varchar(10), [Status.SchedFundingDate], 112) <= convert(varchar(10), getdate() + 1, 112)
我正在尝试解决的当前查询:

[Status.SchedFundingDate]是否在[today]+[1个日历日]或之前

CASE WHEN UPPER(DATENAME(DW, getdate())) = 'FRIDAY'
THEN convert(varchar(10), [Status.SchedFundingDate], 112) <= convert(varchar(10), getdate() + 3, 112)
ELSE convert(varchar(10), [Status.SchedFundingDate], 112) <= convert(varchar(10), getdate() + 1, 112)
END

上面的SQL语句在“上给了我语法错误,您不能在SELECT上使用比较。SQL Server不知道什么是布尔值,您必须使用位

例如,选择1<0是无效的,并且在“@@DateFirst+DatePart weekday”附近给出了相同的错误语法错误,无论DateFirst或Language的设置如何,YourDate-1%7+1将始终返回一个从1到7的整数,其中1对应于Sunday

您可以在case表达式中使用该表达式,通过添加所需的天数来调整周末的日期:

-- Generate some sample data.
with Dates as (
  select GetDate() as ADate, 1 as NumberOfDates
  union all
  select DateAdd( day, 1, ADate ), NumberOfDates + 1
    from Dates
    where NumberOfDates <= 14 )
  -- Demonstrate adjusting weekend dates to the next Monday.
  select ADate, DateName( weekday, ADate ) as Weekday,
    DateAdd( day, case ( @@DateFirst + DatePart( weekday, ADate ) - 1 ) % 7 + 1
      when 1 then 1 -- Sunday.
      when 7 then 2 -- Saturday.
      else 0 end, ADate ) as AdjustedADate
    from Dates;

你应该将结果转换为bit,否则它是intI尝试转换的,它不喜欢“as”部分。你是如何转换的,你得到了什么错误?语法为SELECT CAST1 AS BIT;如果您想要布尔值,我正在用T-SQL编写,我在关键字“as”附近遇到一个错误,语法不正确。castDATENAMEDW,GETDATE='Friday'和[Status.SchedFundingDate]@razimovom时,我编辑了答案,以包含对位的转换。请阅读和,以便更好地理解两者。因为CASE是TSql中的一个表达式,而不是许多其他语言中的流构造控件。将日期或日期时间转换为字符串进行比较是实现目标的错误方法。
-- Generate some sample data.
with Dates as (
  select GetDate() as ADate, 1 as NumberOfDates
  union all
  select DateAdd( day, 1, ADate ), NumberOfDates + 1
    from Dates
    where NumberOfDates <= 14 )
  -- Demonstrate adjusting weekend dates to the next Monday.
  select ADate, DateName( weekday, ADate ) as Weekday,
    DateAdd( day, case ( @@DateFirst + DatePart( weekday, ADate ) - 1 ) % 7 + 1
      when 1 then 1 -- Sunday.
      when 7 then 2 -- Saturday.
      else 0 end, ADate ) as AdjustedADate
    from Dates;