Inline variable initialization in SQL Server 2008
This is one of the cool features that I like in sql server 2008. We can initialize the variable inline. DECLARE @i int = 10 ; Seems to be a simple, but it saves a 'Select /Set' statement You can initialize the variable with any constant including the @@ROWCOUNT /@@SPID/ SCOPE_IDENTITY() etc. SELECT 1 UNION UNION DECLARE @i INT SELECT @i --- 3 GO SELECT 1 UNION UNION UNION DECLARE @i INT SELECT @i --- 3 GO DECLARE @testTab Table (i int INSERT SELECT 1 UNION UNION UNION DECLARE @i INT SELECT @i --- 3 GO
SELECT 2
SELECT 3
=@@ROWCOUNT
SELECT 2
SELECT 3
SELECT 3
=@@ROWCOUNT
identity, j int
)
INTO @testTab
SELECT 2
SELECT 3
SELECT 3
=SCOPE_IDENTITY()
No comments:
Post a Comment