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. Table Variables as Stored Procedure Parameters

Table Variables as Stored Procedure Parameters

Scheduled Pinned Locked Moved Database
databasequestion
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.
  • A Offline
    A Offline
    Alex Deem
    wrote on last edited by
    #1

    Hi, Is it possible to use table variables as parameters to a stored procedure? What i would like to do is: CREATE PROCEDURE [dbo].[spSetBillingPlan_Custom] @ContractNumber integer, @ArgTable TABLE(phasenum integer, perc decimal(5,4)) AS --yadda yadda yadda But it doesnt seem to like the table arguement. If it is not possible, can anyone offer an alternative solution to passing a variable amount of data to a stored proceedure? Thanks and Regards, Alex

    Richard DeemingR M 2 Replies Last reply
    0
    • A Alex Deem

      Hi, Is it possible to use table variables as parameters to a stored procedure? What i would like to do is: CREATE PROCEDURE [dbo].[spSetBillingPlan_Custom] @ContractNumber integer, @ArgTable TABLE(phasenum integer, perc decimal(5,4)) AS --yadda yadda yadda But it doesnt seem to like the table arguement. If it is not possible, can anyone offer an alternative solution to passing a variable amount of data to a stored proceedure? Thanks and Regards, Alex

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

      This code came from one of the SQL Server sites:

      CREATE FUNCTION fn_Split
      (
      @sText varchar(8000),
      @sDelim varchar(20) = ' '
      )
      RETURNS @retArray TABLE
      (
      idx smallint Primary Key,
      value varchar(8000)
      )
      AS
      BEGIN
      DECLARE @idx smallint,
      @value varchar(8000),
      @bcontinue bit,
      @iStrike smallint,
      @iDelimlength tinyint

      SELECT
          @idx = 0,
          @bContinue = 1,
          @sText = LTrim(RTrim(@sText)),
          @iDelimLength = CASE
              WHEN @sDelim Is Null THEN 0
              WHEN @sDelim = 'Empty' THEN 0
              WHEN @sDelim = 'Space' THEN 1
              ELSE DataLength(@sDelim)
          END,
          @sDelim = CASE
              WHEN @sDelim Is Null THEN ''
              WHEN @sDelim = 'Empty' THEN ''
              WHEN @sDelim = 'Space' THEN ' '
              ELSE @sDelim
          END
      
      
      IF NOT (@iDelimlength = 0)
      BEGIN
          WHILE @bcontinue = 1
          BEGIN
      

      --If you can find the delimiter in the text, retrieve the first element and
      --insert it with its index into the return table.

              IF CHARINDEX(@sDelim, @sText)>0
              BEGIN
                  SET @value = LTrim(RTrim(SUBSTRING(@sText,1,CHARINDEX(@sDelim,@sText)-1)))
      
                  INSERT INTO @retArray (idx, value)
                  VALUES (@idx, @value)
      

      --Trim the element and its delimiter from the front of the string.
      --Increment the index and loop.
      SELECT
      @idx = @idx + 1,
      @iStrike = DATALENGTH(@value) + @iDelimlength,
      @sText = LTrim(RTrim(Right(@sText,DATALENGTH(@sText) - @iStrike)))
      END
      ELSE
      BEGIN
      --If you can’t find the delimiter in the text, @sText is the last value in
      --@retArray.
      SET @value = LTrim(RTrim(@sText))
      INSERT INTO @retArray (idx, value)
      VALUES (@idx, @value)
      --Exit the WHILE loop.
      SET @bcontinue = 0
      END
      END
      END
      ELSE
      BEGIN
      WHILE @bcontinue=1
      BEGIN
      --If the delimiter is an empty string, check for remaining text
      --instead of a delimiter. Insert the first character into the
      --retArray table. Trim the character from the front of the string.
      --Increment the index and loop.
      IF DATALENGTH(@sText)>1
      BEGIN
      SET @value = SUBSTRING(@sText,1,1)
      INSERT INTO @retArray (idx, value)
      VAL

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

      1 Reply Last reply
      0
      • A Alex Deem

        Hi, Is it possible to use table variables as parameters to a stored procedure? What i would like to do is: CREATE PROCEDURE [dbo].[spSetBillingPlan_Custom] @ContractNumber integer, @ArgTable TABLE(phasenum integer, perc decimal(5,4)) AS --yadda yadda yadda But it doesnt seem to like the table arguement. If it is not possible, can anyone offer an alternative solution to passing a variable amount of data to a stored proceedure? Thanks and Regards, Alex

        M Offline
        M Offline
        Morten Abrahamsen
        wrote on last edited by
        #3

        As you have correctly pointed out. SQL Server 2000 doesn't allow table variables as input parameters in stored procedures. What you could use instead is the "politically correct" xml document. Pass an xml document (array... ) to the SQL Server, and use the OPENXML statement to process it. :) Morty

        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