开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜