Home All Groups Group Topic Archive Search About
Author
17 Oct 2006 8:57 PM
RON
What's the difference between the following 2 queries especially the
1st line after declaring the variable @OrderCount int in the 2 queries
(both the queries output the same resultset):

--------------------
DECLARE
    @OrderCount int

SET @OrderCount = (SELECT COUNT(OrderID) FROM Orders WHERE UserID = 5)
SELECT @OrderCount AS OrderCount, OrderID FROM Orders WHERE UserID = 5
--------------------

&

--------------------
DECLARE
    @OrderCount int

SELECT @OrderCount  = COUNT(OrderID) FROM Orders WHERE UserID = 5
SELECT @OrderCount AS OrderCount, OrderID FROM Orders WHERE UserID = 5
--------------------

AddThis Social Bookmark Button