Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL: Case value When value contains '+' THEN ...

Status
Not open for further replies.

jluost1

Programmer
Jun 8, 2001
78
US
I would like to achieve the following result:
-------------------------
SELECT name FROM customer
WHERE
(CASE value
WHEN (value IS NOT NULL) AND CONTAINS(value, '+') THEN 0
ELSE CONVERT(INT value)
END) > 0
--------------------------
A few questions:
1. Can I use CONTAINS for NON-fulltext search?
2. Can I put multiple values after WHEN?
3. How can I make above work the way I want.

Thanks.
 
You could try CHARINDEX to see if the + is in the value field. Also can use multiple when clauses...

Code:
SELECT name FROM customer
WHERE 
(CASE 
  WHEN (value IS NOT NULL) AND CHARINDEX('+',value,1) > 0
     THEN 0
  WHEN (value IS NOT NULL) AND CHARINDEX('$',value,1) > 0
     THEN 0
  WHEN isnumeric(value) > 0 THEN CONVERT(INT value)
END) > 0


Mark

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top