The Light
The Light

Reputation: 27021

How to set multiple local variables in one line using T-SQL?

declare @inserted bit
declare @removed bit

I know it's possible to set them like below:

SELECT @inserted = 0, @removed = 0

but would it be possible to make this even simpler and use something like:

SET @inserted, @removed = 0

Many thanks

Upvotes: 16

Views: 29101

Answers (2)

marc_s
marc_s

Reputation: 755541

How about:

declare @inserted BIT = 0, @removed BIT = 0

Works in SQL Server 2008 and up (you didn't specify which version of SQL Server....)

Update: ok, so you're stuck on SQL Server 2005 - in that case, I believe this is the best you can do:

DECLARE @inserted BIT, @removed BIT
SELECT @inserted = 0, @removed = 0

Upvotes: 27

Tomalak
Tomalak

Reputation: 338426

but would it be possible to make this even simpler and use something like:

SET @inserted, @removed = 0

I suppose yo mean

SET @inserted = @removed = 0

No, that is not possible. T-SQL does not support this kind of syntax.

Upvotes: 1

Related Questions