我必须在City表中更新City.Date,并且我在表格中有Interval和Period等列.
Interval列包含yy,ww,dd,qq等值,Period列包含1,2,3等值.
我想尝试像这样更新City.Date:
UPDATE City SET City.date = DATEADD(City.Interval,City.Period,City.date) WHERE CityId = 13
它收到的错误如下:
City.Interval is not recognized DATEADD option.
如何使用City.Interval,City.Period和City.date更新City.Date?
解决方法
您无法参数化间隔位
UPDATE City SET date = CASE Interval WHEN 'yy' THEN DATEADD(yy,Period,date) WHEN 'ww' THEN DATEADD(ww,date) WHEN 'dd' THEN DATEADD(dd,date) WHEN 'qq' THEN DATEADD(qq,date) WHEN ... END WHERE CityId =13