Hi team,
Below query resulted in error. Please help to resolve this error.
Conversion failed when converting date and/or time from character string.
DECLARE @STR VARCHAR (MAX)
Declare @STRAND VARCHAR (MAX)=''
Declare @Where Varchar (MAX)=''
DECLARE @STR_WHERE VARCHAR (MAX) =''
Declare @fromdate datetime='2020-04-10'
SET @STR=' select * from employees_Data'
--set @STR_WHERE=' where Convert(date,DATE_OF_JOINING) = '''+ CAST (@fromdate AS VARCHAR)+''''
set @STR_WHERE='and Convert(date,DATE_OF_JOINING) = CONVERT(date,'''+@fromDate+''')'
PRINT @STR + @Where + @STR_WHERE + ' order by 1 desc'
EXEC (@STR + @Where + @STR_WHERE + ' order by 1 desc')