Vote count:
0
im trying to add a column in where clause in sql server2005, but issue is i have to add it for a given condition like
where condition 1
and condition 2
if(@val !=null and @val = 'test')
begin
and condition 3
end
but when i try this sql server gives me error:
Incorrect syntax near the keyword 'and'. Severity 15 Procedure Name
Incorrect syntax near 'END'. Severity 15 Procedure Name
i did some R&D and found that i should use case statement instead and then i tried this
where condition 1
and condition 2
CASE @val
WHEN 'test' THEN AND condition 3
END
but now its giving error:
Incorrect syntax near the keyword 'CASE'. Severity 15 Procedure Name
can any one help me to sort out the problem thanks.
asked 37 secs ago
Aucun commentaire:
Enregistrer un commentaire