Re: which is better... SET or SELECT?
From: David Portas (REMOVE_BEFORE_REPLYING_dportas_at_acm.org)
Date: 08/02/04
- Next message: Uri Dimant: "Re: Join hints"
- Previous message: Ami Levin: "Join hints"
- In reply to: Anubis: "which is better... SET or SELECT?"
- Next in thread: Jacco Schalkwijk: "Re: which is better... SET or SELECT?"
- Reply: Jacco Schalkwijk: "Re: which is better... SET or SELECT?"
- Reply: Roji. P. Thomas: "Re: which is better... SET or SELECT?"
- Reply: Roji. P. Thomas: "Re: which is better... SET or SELECT?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 2 Aug 2004 10:24:34 +0100
One important difference between SET and SELECT for variable assignment is
the behaviour when no rows are returned from the SELECT statement. If
variables are assigned in the SELECT then the value of the variables will
remain unchanged. Example:
DECLARE @id INTEGER
SET @id = 0
SELECT @id = id
FROM sysobjects
WHERE name = 'does not exist'
SELECT @id -- Returns Zero
SET @id=
(SELECT id
FROM sysobjects
WHERE name = 'does not exist')
SELECT @id -- Returns NULL
-- David Portas SQL Server MVP --
- Next message: Uri Dimant: "Re: Join hints"
- Previous message: Ami Levin: "Join hints"
- In reply to: Anubis: "which is better... SET or SELECT?"
- Next in thread: Jacco Schalkwijk: "Re: which is better... SET or SELECT?"
- Reply: Jacco Schalkwijk: "Re: which is better... SET or SELECT?"
- Reply: Roji. P. Thomas: "Re: which is better... SET or SELECT?"
- Reply: Roji. P. Thomas: "Re: which is better... SET or SELECT?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading