Firstly, I am under the impression that SET
and SELECT
are almost interchangeable. But when I changed the SELECT
to SET
in the following code, it cannot compile.
Can anyone explain to me why is this so ?
Thanks.
-- Create Procedure
CREATE PROCEDURE uspGetAddressCount @City nvarchar(30), @AddressCount int OUT
AS
SELECT @AddressCount = count(*) -- changing 'SELECT' to 'SET' doesn't work
FROM AdventureWorks.Person.Address
WHERE City = @City
-- SQL query to call the procedure
declare @AddressCount int
exec uspGetAddressCount bothell, @AddressCount OUTPUT
select @AddressCount -- Didn't know SELECT can be used to print values ?