Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sql server Identity issue

Sql server Identity issue

Scheduled Pinned Locked Moved Database
databasesql-serversysadminsaleshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pranay Rana
    wrote on last edited by
    #1

    I have query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName , CustomerAddress , CustomerEmail , CustomerPhone ) values ( ‘werw12e’ , ‘jkj12kj’ , ‘3212423sdf’ , ‘1212121′ ) select @str_CustomerID= scope_identity() after execution it returns null in my parameter i want to get value of identity how can i do that the main issue over here is "IMDECONP38"- server name that i used if i remove this i can able to get the value of identity in my parameter

    S 1 Reply Last reply
    0
    • P Pranay Rana

      I have query like below declare @str_CustomerID int Insert into IMDECONP38.[Customer].dbo.CustomerMaster ( CustomerName , CustomerAddress , CustomerEmail , CustomerPhone ) values ( ‘werw12e’ , ‘jkj12kj’ , ‘3212423sdf’ , ‘1212121′ ) select @str_CustomerID= scope_identity() after execution it returns null in my parameter i want to get value of identity how can i do that the main issue over here is "IMDECONP38"- server name that i used if i remove this i can able to get the value of identity in my parameter

      S Offline
      S Offline
      Stryder_1
      wrote on last edited by
      #2

      Are you running this script connected to server "IMDECONP38" or is that a linked server from which you are running the query?

      P 1 Reply Last reply
      0
      • S Stryder_1

        Are you running this script connected to server "IMDECONP38" or is that a linked server from which you are running the query?

        P Offline
        P Offline
        Pranay Rana
        wrote on last edited by
        #3

        yes its from link server

        S 1 Reply Last reply
        0
        • P Pranay Rana

          yes its from link server

          S Offline
          S Offline
          Stryder_1
          wrote on last edited by
          #4

          scope_identity and @@Identity only works on the server its executed on, so it won't return a value from a linked server. You would need to create a stored proc on the linked server that returns the scope_identity value. You could then call that from your query. See here for more information: http://msdn.microsoft.com/en-us/library/ms187342.aspx

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups