Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-11-08
3
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

705 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