Re: which is better... SET or SELECT?
From: Roji. P. Thomas (lazydragon_at_nowhere.com)
Date: 08/02/04
- Next message: Rick Bean: "Re: Suggestion for a datagrid ?"
- Previous message: Greg Linwood: "Re: Accessing items in a collection using sp_OAGetProperty"
- In reply to: David Portas: "Re: which is better... SET or SELECT?"
- Next in thread: Roji. P. Thomas: "Re: which is better... SET or SELECT?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 2 Aug 2004 18:10:52 +0530
One more thing to be careful is, if the SELCT includes an Aggreagate
function,
it returns NULL istead of zero
DECLARE @id INTEGER
SET @id = 0
SELECT @id = Max(id)
FROM sysobjects
WHERE name = 'does not exist'
SELECT @id -- Returns NULL
DECLARE @id INTEGER
SET @id = 0
SELECT @id = id
FROM sysobjects
WHERE name = 'does not exist'
SELECT @id -- Returns Zero
-- Roji. P. Thomas Net Asset Management https://www.netassetmanagement.com "David Portas" <REMOVE_BEFORE_REPLYING_dportas@acm.org> wrote in message news:ObednZbR7r0elZPcRVn-uA@giganews.com... > 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: Rick Bean: "Re: Suggestion for a datagrid ?"
- Previous message: Greg Linwood: "Re: Accessing items in a collection using sp_OAGetProperty"
- In reply to: David Portas: "Re: which is better... SET or SELECT?"
- Next in thread: Roji. P. Thomas: "Re: which is better... SET or SELECT?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|