SELECT @sql='
select
*
from (
select ''Ongoing'' AS Ongoing,
Coalesce(COUNT(project),0) AS project, Coalesce(COUNT(year(u.PlannedStartDate)),0) as [y]
from Projects u WHERE
u.actualstartdate IS NULL
AND u.Startdate < ''+GETDATE()+''
AND ID ='''+@ID+'''
) Data
PIVOT (
COUNT(project)
FOR [y]
IN (
' + @Years + '
)
) PivotTable
'
在这里我想传递当前日期但它不起作用..这是因为 GETDATE() 的值没有出现在字符串中