Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Throw Error 7 34
Convert VBA UDF to SQl SERVER UDF 4 49
Need help with a query 14 37
SQL Distinct Question 3 14
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

756 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