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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Using select or set with exec

Using select or set with exec

Scheduled Pinned Locked Moved Database
databasesql-serversysadmin
3 Posts 3 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.
  • C Offline
    C Offline
    ChrisFarrugia
    wrote on last edited by
    #1

    Dear All, I need to set the value of a variable with the result of a stored procedure. I need something on these lines: set @productCount = exec procGetCount I did not manage to get this to work. I am using Microsoft Sql Server 7 and 2000. Thanks a lot, Chris

    A S 2 Replies Last reply
    0
    • C ChrisFarrugia

      Dear All, I need to set the value of a variable with the result of a stored procedure. I need something on these lines: set @productCount = exec procGetCount I did not manage to get this to work. I am using Microsoft Sql Server 7 and 2000. Thanks a lot, Chris

      A Offline
      A Offline
      Alsvha
      wrote on last edited by
      #2

      You can't (in those versions at least) that I know of. Either you have to make it into a function or use output parameters.

      --------------------------- Blogging about SQL, Technology and many other things

      1 Reply Last reply
      0
      • C ChrisFarrugia

        Dear All, I need to set the value of a variable with the result of a stored procedure. I need something on these lines: set @productCount = exec procGetCount I did not manage to get this to work. I am using Microsoft Sql Server 7 and 2000. Thanks a lot, Chris

        S Offline
        S Offline
        SomeGuyThatIsMe
        wrote on last edited by
        #3

        in sql 2000 sp4(mabye in other versions of 2000 but i dont have any to test on) EXEC @var = procGetCount but you have to RETURN the value out of the stored procedure for it to work and sql 2000 can only return int values. example procedure code DECLARE @var INTEGER SET @var = 3 RETURN @var you can also put SELECT @var before the return if you need to as well.

        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