Hiagain I have a problem in Dynamic SQL.I have written this storedprocedure but it has an Error:@docdtl nvarchar(50)=null, @facnum nvarchar(50)=null, @creditor int=0, @debtor int=0, @office intASDECLARE @Cmd nvarchar(4000),@Where nvarchar(4000)set @Where=' where OfficeID='+convert(nvarchar(50),@office)+' and (FacNum='''+@facnum+''''')UNIONselect * from Document where OfficeID='+convert(nvarchar(50),@office)+' and (DocDetails='''+@docdtl+''''')'set @Cmd='select * from Document'if Creditor<>0* @Where=@Where+' UNION select * from Document where OfficeID='+convert(nvarchar(50),@office)+' and (Creditor='+convert(nvarchar(50),@creditor)+')'if Debtor<>0* @Where=@Where+' UNION select * from Document where OfficeID='+convert(nvarchar(50),@office)+' and (Debtor='+convert(nvarchar(50),@debtor)+')'if @Where<>''set @Cmd=@Cmd+@WhereExec @Cmd
and the Error is:Inncorrect syntax near @Where for 2 * lines.Sara Dajer