Solved

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

Posted on 2006-11-08
3
167 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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Updating a column using a lookup on another table. 6 19
SQL Server Question 5 26
recover sqlserver db 8 55
sql server group by every 2hrs 5 7
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

910 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

20 Experts available now in Live!

Get 1:1 Help Now