SQL Difference Between Parameter and value
Sorry if my heading was a bit misleading but not entirely sure how to phrase it.
Why would there be a difference between the below two statements:
SELECT *
FROM tbl1 LEFT OUTER JOIN
tbl2 ON tbl1.num = tbl2.tbl1Num LEFT OUTER JOIN
tbl3 ON tbl2.num = tbl3.tbl2Num
WHERE tbl2.intNum = 123 OR 123 = -1
AND
DECLARE @intNum int = 123
SELECT *
FROM tbl1 LEFT OUTER JOIN
tbl2 ON tbl1.num = tbl2.tbl1Num LEFT OUTER JOIN
tbl3 ON tbl2.num = tbl3.tbl2Num
WHERE tbl2.intNum = @intNum OR @intNum = -1
We ran the above two queries and it actually gave us differen开发者_StackOverflowt results? We ended up changing it to a Union to solve the problem but I would really like to understand why this happened.
Thanks in advance!
You're missing the parameter type:
declare @intNum int = 123
精彩评论