Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 unable to understand the script ???

Author  Topic 

SanjaySutar
Starting Member

18 Posts

Posted - 2008-04-04 : 04:56:35
Hi,
i have a stored procedure as :
----------------------------------------------------------
CREATE PROCEDURE Insert_tblAccount
@Name varchar(50),
@Password varchar(20),
@StatusID int,
@AccountType int,
@DOI datetime,
@ROI varchar(500)
AS

Declare @NewID Numeric(18)

BEGIN

SET NOCOUNT ON

INSERT INTO [tblAccount](Name, [Password], StatusID,AccountType, DOI, ROI )
VALUES(@Name, @Password, @StatusID, @AccountType, @DOI, @ROI)

Set @NewID = SCOPE_IDENTITY()
Select @NewID As NewID
END
----------------------------------------------------------------

i could not understand the line
Select @NewID As NewID
bcoz i have learned that NewId() function returns unique identifier
but above code returns same value as SCOPE_IDENTITY.

So can anybody make me clear what's going on ?????

thanx in advance

San

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-04 : 05:07:05
Its just a variable to which the result of SCOPE_IDENTITY is assigned. ANd the statement in bold just selects its value with a alias name NewID. notice that you dont have () after NewID so it is not a function invocation.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-04 : 06:23:20
You should note that Newid is followed by AS. So it is alias name

Select newid(),newid() as newid

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -