当我将硬编码日期(突出显示)更改为 ?
它返回了转换错误消息。修复是什么?感谢我能得到的所有帮助。
SET NOCOUNT ON
DECLARE @lastdayofweek DATETIME
DECLARE @firstdayofweek DATETIME
DECLARE @previouslastdayweek DATETIME
DECLARE @previousfirstdayweek DATETIME
SET @lastdayofweek = '2018-08-03'
SET @firstdayofweek = dateadd(day, - 6, @lastdayofweek)
SET @previouslastdayweek = dateadd(day, - 1, @firstdayofweek)
SET @previousfirstdayweek = dateadd(day, - 6, @previouslastdayweek)
SELECT DISTINCT b.unittype
,b.propertyid
,d.propertyname1
,count(CASE
WHEN b.ActMadeReadyDate <= @previouslastdayweek
AND b.occustatus IN ('NA')
AND b.calcdate = @previouslastdayweek
THEN b.UnitType
END) AS 'Last Week Unit Type Not Rent Ready'
,count(CASE
WHEN b.occustatus IN (
'VL'
,'VA'
)
AND b.calcdate = @lastdayofweek
THEN b.unitid
END) AS 'Vacants'
,count(CASE
WHEN b.ActMadeReadyDate <= @lastdayofweek
AND b.occustatus IN (
'VA'
,'VL'
)
AND b.calcdate = @lastdayofweek
THEN b.unitid
END) AS 'Rent Ready'
,count(CASE
WHEN b.ActMadeReadyDate IS NULL
AND b.occustatus IN ('VA')
AND b.calcdate = @previousfirstdayweek
THEN b.unitid
END) AS 'Rent not Ready'
FROM unitwithstatus b
INNER JOIN property d ON b.propertyid = d.propertyid
LEFT JOIN lease a ON a.propertyid = b.propertyid
AND a.bldgid = b.bldgid
AND a.unitid = b.unitid
AND a.moveindate >= @previousfirstdayweek
AND a.moveindate <= @previouslastdayweek
WHERE b.propertyid LIKE '01___'
AND b.unitstatus <> 'W'
AND b.unitstatus <> 'D'
--and lastdayofweek = ? --'" & Range("J4") & "'
--and b.PropertyId in ('01TRL')
GROUP BY b.unittype
,b.propertyid
,d.propertyname1
这是如何使用传入的值作为参数。
—
jrk properties
设置@lastdayofweek =
—
jrk properties
将套装@lastdayofweek = '08 / 03/2018'更改为? (尝试将其链接到excel)但它返回“无效参数号”错误
—
jrk properties
我尝试了你建议的格式。同样的错误
—
jrk properties
我可以发给你整个查询吗?感谢您的回复
—
jrk properties