0
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
'

Here I want to pass the cur date but it's not working.. this is because the value of GETDATE() is not coming in the string

1
  • Welcome to StackOverflow: if you post code, XML or data samples, please highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it! Commented Jul 11, 2012 at 14:36

3 Answers 3

2

change AND u.Startdate < ''+GETDATE()+'' to AND u.Startdate < GETDATE()

Sign up to request clarification or add additional context in comments.

Comments

1

Just remove the quotes around it I would think

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 '

1 Comment

This will not work in a string function. It takes as GETDATE() only not the date value.
0

Try casting GETDATE() to a varchar like this: CAST(GETDATE() AS varchar)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.