If @PCode <> ''
BEGIN
If IsNumeric(@PCode) = 1
Set @SQL =@SQL+' And p.PCode like '''+@PCode+'%'''
Else If Ascii(@PCode) > 64 Or Ascii(@PCode) < 123
Set @SQL =@SQL+' And p.PName like ''%'+@PCode+'%'''
Else
Set @SQL =@SQL+ ' And p.PyName like ''%'+@PCode+'%'''
End
If @ClientCode<>''
Begin
If IsNumeric(@ClientCode) = 1
Set @SQL = @SQL+' And c.ClientCode like ''' +@ClientCode+ '%'''
Else If Ascii(@ClientCode) > 64 Or Ascii(@PCode) < 123
Set @SQL = @SQL+' And c.PYName like ''%'+@ClientCode+'%'''
Else
Set @SQL = @SQL+' And c.ClientName like ''%'+@ClientCode+ '%'''
End
If @PCode <> '' BEGIN If IsNumeric(@PCode) = 1 Set @SQL =@SQL+' And p.PCode like '''+@PCode+'%''' Else If Ascii(@PCode) > 64 Or Ascii(@PCode) < 123 Set @SQL =@SQL+' And p.PName like ''%