I have a text column and the data in the text columns are as below:
Rob goes to school,get punished
Rob goes to school
Rob does not goes to school,get punished
When trying to write a query using case statement like
CASE
WHEN (PATINDEX('%Rob goes to school%',value) > 0) OR
(PATINDEX('%Rob is ill%',value) > 0 ) AND
(PATINDEX(%get punished%',value) > 0) THEN
'DONE'
It should select only the 1st statement but instead it is picking both the 1st and 2nd statement with ‘DONE’. Any suggestion how to do a pattern match in this case?
I am using SQL Sever 2005/2008
Operator precedence and not enough parenthesis probably
You have
x OR y AND zwhich is actuallyx OR (y AND z). Do you want want(x OR y) AND z?true OR (false AND false)which givestrue(true OR false) AND falseto givefalseSo the SQL should be