tsql - Datetime conversion / mixed variables in dynamic SQL -
I have a table that has more than one timeout column - I have a question that accepts a parameter to specify which date column to compare with another date Required. Here is my query effort - The return error - Try it out: TblDate1 ,
TblDate2 ,
TblDate3 , etc ...
sp_executesql
announcement @DateColumn nvarchar (128) set @DateColumn = 'TblDate2' declared @DateStart date set @DateStart = DATEADD (d, -7, getdate ()) Execute messages from N'SELECT * where @DueartinType & lt; @DateColumnIN ', N' @ DateStartIN datetime, @DateColumnIN nvarchar (128) ', @DateStartIN = @DateStart, @DateColumnIN = @DateColumn
Conversions in message 241, level 16, state 1, line 1 fails when the character changes the date and / or time from the string.
DECLARE @DateColumn VARCHAR (128) SET @DateColumn = 'TblDate2' DECLARE @DateStart DATETIME SET @DateStart = DATEADD (D, -7, GETDATE ()) DECLARE @pvsSQL NVARCHAR (256) SET @pvsSQL = 'SELECT * with messageable WHERE' @DateColumn + '& Lt; '' '+ Convert (VARCHAR, @DateStart) +' ''; Executed 'sp_executesql @pvsSQL
Comments
Post a Comment