栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

SQL Server Operand类型冲突:日期与int不兼容

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SQL Server Operand类型冲突:日期与int不兼容

您的问题在于该

DateCalendarValue + 1
部分。尝试使用
DATEADD()
,如下所示:

declare @DateCalendarStart  date,        @DateCalendarEnd    date,        @FiscalCounter      date,        @FiscalMonthOffset  int;set @DateCalendarStart = '2011-01-28';set @DateCalendarEnd = '2012-10-26';-- Set this to the number of months to add or extract to the current date to get the beginning -- of the Fiscal Year. Example: If the Fiscal Year begins July 1, assign the value of 6 -- to the @FiscalMonthOffset variable. Negative values are also allowed, thus if your -- 2012 Fiscal Year begins in July of 2011, assign a value of -6.set @FiscalMonthOffset = 3;with DateDimensionas(    select  @DateCalendarStart as DateCalendarValue, dateadd(m, @FiscalMonthOffset, @DateCalendarStart) as FiscalCounter    union all    select  DATEADD(DAY, 1, DateCalendarValue), -- Using a DATEADD() function here works for SQL Server DATEADD(m, @FiscalMonthOffset, (DATEADD(DAY, 1, DateCalendarValue))) as FiscalCounter    from    DateDimension     where   DATEADD(DAY, 1, DateCalendarValue) < = @DateCalendarEnd)SELECt * FROM DateDimension OPTION (MAXRECURSION 1000)

编辑:我不知道您的原始代码是否要使用该

MAXRECURSION
选项,但是如果您不知道我建议您阅读此内容。基本上,在这种情况下,这意味着您可以使用CTE列出1,000个日期。如果您需要的更多,则必须将其更改为1000以符合您的需求。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/574925.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号