;WITH WCTE AS( Select Header, Convert(DateTime,Value,110) ServiceDate2 from tblUdrElement Where 1=1 and Header = 'Service Date' )SELECT * FROM WCTE where ServiceDate2 >= '2012-01-01 00:00:00.000' order by 1
The above query give me the conversion error. But when I save the CTE query in a temp table and then apply the condition on the temp table, it works fine.
Select Header, Convert(DateTime,Value,110) ServiceDate2 into #tbl from tblUdrElement Where 1=1 and Header = 'Service Date' Order by ServiceDate2 Select * from #tbl where ServiceDate2 >= convert(datetime,'2013-01-10 00:00:00') drop table #tbl
Can someone explain this please...?
Please visit my Blog for some easy and often used t-sql scripts
My BizCard