Solved

How Can I get the Scope_Identity() after inserting a new row

Posted on 2006-11-08
3
166 Views
Last Modified: 2008-03-04
Hello guys,

I am testing my store procedure but I having an error
Server: Msg 170, Level 15, State 1, Procedure STP_REAJUSTE_PRECO_FABRIL, Line 17
Line 17: Incorrect syntax near 'REAJPRECOFABRIL_SEQ'.

After inserting I need to get the ID in this variable @ID

CREATE PROCEDURE STP_REAJUSTE_PRECO_FABRIL
  @USO VARCHAR(20)
AS

DECLARE @ID INT

  INSERT INTO REAJPRECOFABRIL_SEQ (RFB_USO) VALUES ('ALEX')  
  SELECT @ID= SCOPE_IDENTITY() REAJPRECOFABRIL_SEQ
  SELECT @ID
0
Comment
Question by:hidrau
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 17897167
CREATE PROCEDURE STP_REAJUSTE_PRECO_FABRIL
  @USO VARCHAR(20)
AS

DECLARE @ID INT

  INSERT INTO REAJPRECOFABRIL_SEQ (RFB_USO) VALUES ('ALEX')  
  SELECT @ID= SCOPE_IDENTITY()

  SELECT @ID
GO
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17897208
CREATE PROCEDURE STP_REAJUSTE_PRECO_FABRIL
  @USO VARCHAR(20)
AS
DECLARE @ID INT
  SET NOCOUNT ON

  INSERT INTO REAJPRECOFABRIL_SEQ (RFB_USO) VALUES ('ALEX')  
  SELECT @ID= SCOPE_IDENTITY()
  SELECT @ID REAJPRECOFABRIL_SEQ
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17897388
hidrau,
> SELECT @ID= SCOPE_IDENTITY() REAJPRECOFABRIL_SEQ
>   SELECT @ID

or instead of the above


SELECT  SCOPE_IDENTITY() REAJPRECOFABRIL_SEQ
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now