sql server - how to execute tje second half of or only when first one fails
Posted
by
fn79
on Stack Overflow
See other posts from Stack Overflow
or by fn79
Published on 2012-10-04T21:11:42Z
Indexed on
2012/10/04
21:38 UTC
Read the original article
Hit count: 123
sql
|sql-server
Suppose I have a table with following records
value text
company/about about Us
company company
company/contactus company contact
I have a very simple query in sql server as below. I am having problem with the 'or' condition. In below query, I am trying to find text for value 'company/about'. If it is not found, then only I want to run the other side of 'or'. The below query returns two records as below
value text
company/about about Us
company company
Query
select
*
from
tbl
where
value='company/about' or
value=substring('company/about',0,charindex('/','company/about'))
How can I modify the query so the result set looks like
value text
company/about about Us
© Stack Overflow or respective owner