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. return value,

return value,

Scheduled Pinned Locked Moved Database
databasehelptutorialquestion
4 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.
  • H Offline
    H Offline
    Hema Bairavan
    wrote on last edited by
    #1

    Hi, @Text ='%hema%' @itemcount int SET @SQL ='SELECT COUNT(*) FROM dbo.table WHERE (LOWER(column) LIKE LOWER('+@Text+') OR LOWER(column) LIKE LOWER('+@Text+')) exec @SQL i want out put of that select (i.e count(*)) in the local variable @itemcount. if i give like set @itemcount = EXEC @SQL i m getting syntax error, how to take that?

    B 1 Reply Last reply
    0
    • H Hema Bairavan

      Hi, @Text ='%hema%' @itemcount int SET @SQL ='SELECT COUNT(*) FROM dbo.table WHERE (LOWER(column) LIKE LOWER('+@Text+') OR LOWER(column) LIKE LOWER('+@Text+')) exec @SQL i want out put of that select (i.e count(*)) in the local variable @itemcount. if i give like set @itemcount = EXEC @SQL i m getting syntax error, how to take that?

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      Example:

      declare @itemcount int
      set @itemcount = (select isnull(count(*),0) from tablename where columnname=conditionvalue)


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

      H 1 Reply Last reply
      0
      • B Blue_Boy

        Example:

        declare @itemcount int
        set @itemcount = (select isnull(count(*),0) from tablename where columnname=conditionvalue)


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post. www.aktualiteti.com

        H Offline
        H Offline
        Hema Bairavan
        wrote on last edited by
        #3

        thanks for your response blue. My question is executing the query dynamically that is using EXEC 'query' i need this output in a variable. i hope you can get me or read my prev message fully

        D 1 Reply Last reply
        0
        • H Hema Bairavan

          thanks for your response blue. My question is executing the query dynamically that is using EXEC 'query' i need this output in a variable. i hope you can get me or read my prev message fully

          D Offline
          D Offline
          DarrenShultz
          wrote on last edited by
          #4

          You may want to take a look at the sp_executesql system stored procedure: http://msdn.microsoft.com/en-us/library/ms188001.aspx[^] This allows you execute the dynamic SQL string, as well as specify parameter definitions and parameter assignments that can bind local SQL variables to the dynamic SQL call.

          DECLARE @InputParam int,
          @OutputParam int

          EXECUTE sp_executesql 'query',
          N'@DynamicInputParam int, @DynamicOutputParam int OUTPUT',
          @DynamicInputParam = @InputParam,
          @DynamicOutputParam = @OutputParam OUTPUT

          Within 'query', use the dynamic parameters/variables defined in the 2nd parameter (@DynamicInputParam and @DynamicOutputParam). Within 'query', these variables will initially contain the values of (@InputParam and @OutputParam). If a dynamic parameter is defined as an OUTPUT parameter (@DynamicOutputParam), any assignment to that variable will be reflected in the local variable (@OutputParam) after the call to sp_executesql.

          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