I have this sql:
SELECT
sa.answertext
FROM dbo.tblsurveyanswer sa
INNER JOIN dbo.tblsurvey s
ON s.surveyid = sa.surveyid
INNER JOIN dbo.tblquestion q
ON q.questionid = sa.questionid
INNER JOIN dbo.tblshqscriteria c
ON c.shqscriteriaid = q.shqscriteriaid
INNER JOIN dbo.tblshqsdescription d
ON d.shqsdescriptionid = q.shqsdescriptionid
INNER JOIN dbo.tblrepairpercentage rp
ON rp.repairpercentageid = sa.repairpercentageid
WHERE
(c.shqscriteria = 'qwerty')
OR
(c.shqscriteria = 'zxcvb' AND ISNUMERIC(sa.answertext) = 1 AND CAST(sa.answertext AS float) < 5)
First time I execute it fails with “Error converting data type varchar to float.”
Second time* I execute it succeeds – returning no rows because there are no ‘qwerty’ or ‘zxcvb’ shqscriteria
*actually sometimes I have to hit execute up to 8 times before I get the failure
As long as you’re not using aggregates, you should be able to rely on CASE’s order of execution:
Note however that
ISNUMERIC(col) = 1does not always mean thatcolis eligible to be converted to a specific numeric type.