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

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

SELECT @newLinkId = Link_Id FROM inserted what to use for "inserted"?

hello experts,

the line "SELECT @newLinkId = Link_Id FROM inserted" is wrong.
Please tell me what to use instead of inserted.
Thanks a lot!

CREATE PROCEDURE [dbo].[Linksummary_CreateNewLink]

  @Linkname nvarchar(50),
  @Linkdescr nvarchar(100),
  @Linkurl nvarchar(500),
  @CategoryId int

AS
INSERT Link
      (
            Link_Name,
            Link_Descr,
            Link_Url
      )
      VALUES
      (
            @Linkname,
            @Linkdescr,
            @Linkurl
      )

      DECLARE @newLinkId int
      SELECT @newLinkId = Link_Id FROM inserted

      INSERT Category_Link
      (
            Category_Id,
            Link_Id
      )
      VALUES
      (
            @CategoryId,
            @newLinkId

      )
RETURN @@IDENTITY
0
arthrex
Asked:
arthrex
2 Solutions
 
Patrick MatthewsCommented:
Hello arthrex,

Are you even allowed to use inserted or deleted outside of triggers?

In any event, is Link_ID an identity column?  If so, then just rely on @@IDENTITY for your
answer...

Regards,

Patrick
0
 
SQL_SERVER_DBACommented:
    DECLARE @newLinkId int
      SET @newLinkId = (SELECT Link_Id FROM inserted)
0
 
arthrexAuthor Commented:
No i'm not allowed :-) but I didn't know better... so I just wort it like that to explain my problem better...
Thanks! @@identity worked... too easy to imagine..
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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