[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 422
  • Last Modified:

Declare varible to hold Scope_Identity() problem

this portion of my stored procedure gives me an "incorrect syntax" error.

DECLARE @NewResourceID      int
SELECT SCOPE_IDENTITY() AS @NewResourceID
0
dba123
Asked:
dba123
  • 2
  • 2
1 Solution
 
sajuksCommented:
select @NewResourceID = SCOPE_IDENTITY()
0
 
sajuksCommented:
Thanks for the points and grade
0
 
dba123Author Commented:
quick question.  Now that I changed it to a parameter, I am not able to use that in my queryset in my asp page

-- ### Get New ResourceID
DECLARE @NewResourceID      int
SELECT @NewResourceID = SCOPE_IDENTITY()


so this doesn't work anymore because before, I was holding the identity in a variable before resorting to declaring a parameter:

Set Query = objConnection.Execute(strSQL)

Session("LastResourceID") = Query("NewResourceID")


0
 
dba123Author Commented:
my complete sp is:


ALTER              PROCEDURE sp_Add_Resource
      @OwnerID                  int = NULL,
      @CreatedByID                  int = NULL,
      @LocationID                  int = NULL,
      @ResourceTypeID                  int = NULL,
      @ResourceName                     varchar(50),
      @DiskSizeID                  int = NULL,
      @CreatedDate                  datetime,
      @CPUTypeID                  int = NULL,
      @CPUSpeedID                  int = NULL,
      @BrandID                  int = NULL,
      @RAMAmountID                  int = NULL,
      @SerialNumber                  varchar(50),
      @OSID                        int = NULL
AS

SET NOCOUNT ON

-- ### Insert Resource
INSERT INTO ERD.dbo.tbl_Resource
(OwnerID, CreatedByID, LocationID, ResourceTypeID, ResourceName, SerialNumber, CreatedDate)
VALUES
(@OwnerID, @CreatedByID, @LocationID, @ResourceTypeID, @ResourceName, @SerialNumber, @CreatedDate)

-- ### Get New ResourceID
DECLARE @NewResourceID      int
SELECT @NewResourceID = SCOPE_IDENTITY()

-- ### Insert Resouce Attributes for Server/PC
INSERT INTO ERD.dbo.tbl_RServer_PC
(ResourceID, OSID, DiskSizeID, CPUTypeID, CPUSpeedID, BrandID, RAMAmountID, CreatedDate)
VALUES
(@NewResourceID, @OSID, @DiskSizeID, @CPUTypeID, @CPUSpeedID, @BrandID, @RAMAmountID, @CreatedDate)

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now