I am getting a "Conversion failed when converting date and/or time from character string." error when executing this sample dynamic
Would anyone be so kind as to help me out with the conversion?
If I change @whatDate to varchar(10), I get no records returned when I know they exist... Also, I need this to be dynamics SQL....
declare @whatDate datetime;
declare @whatDB char(20);
declare @sql nvarchar(4000);
set @whatDate = '02/05/2013'
set @whatDB = 'TEST';
set @sql = 'select ard.aaa, ard.bbb, ard.ccc,
ba.aaa, ba.bbb from ' + @whatDB + '.dbo.myTable ard ' + 'inner join ' + @whatDB + '.dbo.myTable2 ba on ard.aaa = ba.aaa ' + 'where ard.bbb in(''A'',''B'',''C'') and ard.testDate = ' + @whatDate + 'order by ard.aaa desc'