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. It Should Print 12 but the output is NULL , Please tell me How to SET VALUE For the VAriable declare outside the SQL Text cretaed for dynamic query

It Should Print 12 but the output is NULL , Please tell me How to SET VALUE For the VAriable declare outside the SQL Text cretaed for dynamic query

Scheduled Pinned Locked Moved Database
databasesharepointtutorial
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    <pre lang="vb">DECLARE @CheckQuantity INT
    SET @ParmDefinition = N'@CheckQuantity INT'
    SET @SQL = N'
    SET @CheckQuantity= 12'
    PRINT @SQL

            EXEC \[dbo\].sp\_executesql @SQL, @ParmDefinition,
            @CheckQuantity=@CheckQuantity;
            PRINT @CheckQuantity</pre>
    

    It Should Print 12 but the output is NULL , Please tell me How to SET VALUE For the VAriable declare outside the SQL Text cretaed for dynamic query

    L Richard DeemingR 2 Replies Last reply
    0
    • L Lost User

      <pre lang="vb">DECLARE @CheckQuantity INT
      SET @ParmDefinition = N'@CheckQuantity INT'
      SET @SQL = N'
      SET @CheckQuantity= 12'
      PRINT @SQL

              EXEC \[dbo\].sp\_executesql @SQL, @ParmDefinition,
              @CheckQuantity=@CheckQuantity;
              PRINT @CheckQuantity</pre>
      

      It Should Print 12 but the output is NULL , Please tell me How to SET VALUE For the VAriable declare outside the SQL Text cretaed for dynamic query

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      any one who has solution for this

      1 Reply Last reply
      0
      • L Lost User

        <pre lang="vb">DECLARE @CheckQuantity INT
        SET @ParmDefinition = N'@CheckQuantity INT'
        SET @SQL = N'
        SET @CheckQuantity= 12'
        PRINT @SQL

                EXEC \[dbo\].sp\_executesql @SQL, @ParmDefinition,
                @CheckQuantity=@CheckQuantity;
                PRINT @CheckQuantity</pre>
        

        It Should Print 12 but the output is NULL , Please tell me How to SET VALUE For the VAriable declare outside the SQL Text cretaed for dynamic query

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        You need to make the parameter an OUTPUT parameter. https://support.microsoft.com/kb/262499[^]

        DECLARE @CheckQuantity INT;
        SET @ParmDefinition N'@CheckQuantity INT OUTPUT';
        SET @SQL = N'SET @CheckQuantity= 12';
        PRINT @SQL;

        EXEC [dbo].sp_executesql @SQL, @ParmDefinition, @CheckQuantity = @CheckQuantity OUTPUT;
        PRINT @CheckQuantity;


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        L 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          You need to make the parameter an OUTPUT parameter. https://support.microsoft.com/kb/262499[^]

          DECLARE @CheckQuantity INT;
          SET @ParmDefinition N'@CheckQuantity INT OUTPUT';
          SET @SQL = N'SET @CheckQuantity= 12';
          PRINT @SQL;

          EXEC [dbo].sp_executesql @SQL, @ParmDefinition, @CheckQuantity = @CheckQuantity OUTPUT;
          PRINT @CheckQuantity;


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Thank you friend it's working now

          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