My scripts as following,
declare @collectDte_From date
declare @collectDte_To date
declare @chequeNo varchar(20)
Declare @SQL VarChar(max)
SELECT @SQL = 'select crtDte as tarikhKutipan, upper(chequeNo) as chequeNo , chequeDte,
zakatAmount, upper(t2.descrp) as chequeStat
from dbo.paymentCheque_SPZB t1
inner join dbo.chequeStat t2
on t1.chequeStat=t2.idx'
if @collectDte_From is null and @collectDte_To is null and @chequeNo is null
Begin
SELECT @SQL = @SQL
End
else
Begin
SELECT @SQL = @SQL + ' where 1=1 '
End
if @collectDte_From is not null and @collectDte_To is not null
Begin
SELECT @SQL = @SQL + 'and CONVERT(date,crtDte)>=' + @collectDte_From + ' '
End
Exec ( @SQL)
I got an error as following,
Msg 402, Level 16, State 1, Line 24
The data types varchar(max) and date are incompatible in the add operator.
Please help me