Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-11-08
3
Medium Priority
?
177 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 2000 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 143

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

783 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