Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Like % problem

Author  Topic 

rinu.urs
Starting Member

4 Posts

Posted - 2009-10-05 : 23:37:08
hi all,


i have a problem please see the query




select * from [dbo].[vItrisRepository] where id = '" & id.Text & "'" ' which works fine

and another one

select * from [dbo].[vItrisRepository] where name like '%" & name.Text & " % ' " ' which works fine


But when i AND it then its not



select * from [dbo].[vItrisRepository] where id = '" & id.Text & "' and name like '%" & name.Text & " % ' "'"



and i know there is common rows
if any one knows please tell me why its happening i will be really greatful

Thanks and Regards
roma

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2009-10-06 : 01:49:30
You seem to have extra spaces before & after your last % character which would affect it.
Maybe your name.text contains underscores or other characters that have special meaning to the LIKE clause.

A couple of unrelated tips:
You should always use parameters, not generate SQL statements.
If your ID is a number, do not convert it to a string.
Go to Top of Page
   

- Advertisement -