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
 Using Like % operator

Author  Topic 

vaddi
Posting Yak Master

145 Posts

Posted - 2007-04-23 : 12:42:07
hello,

I got a condition in the query , as shown below:

where nt.Project_type='A' and nt.status='Done' and nt.project_id like '06%'

I also need to add an additional condition : like '07%'. How can I do this, i. e I need the projects where the type = A , status = Done and project_id starting with 06 and 07.

Thanks for any help

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-04-23 : 12:45:07
[code]
where nt.Project_type='A' and nt.status='Done' and (nt.project_id like '06%' OR nt.project_id like '07%')
[/code]

Note when you have a mixture of AND/OR conditions, the parantheses are very important.



************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

cvraghu
Posting Yak Master

187 Posts

Posted - 2007-04-23 : 12:45:55
Read the help for SELECT/WHERE clauses in BOL.

where nt.Project_type='A' and nt.status='Done' and
(nt.project_id like '06%' or nt.project_id like '07%')
Go to Top of Page

vaddi
Posting Yak Master

145 Posts

Posted - 2007-04-23 : 12:49:09
Thank you very much for the replies.

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-23 : 12:49:44
This seems easier

where nt.Project_type='A' and nt.status='Done' and nt.project_id like '0[67]%'


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -