Redirect the output to a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lazydev
    New Member
    • Mar 2008
    • 2

    Redirect the output to a variable

    Here's my code just redirect the output to a variable or out statement
    any suggestions

    alter proc r (@id INT)
    as
    BEGIN

    DECLARE @input VARCHAR(800)
    DECLARE @c_input INT
    DECLARE @i_Input INT
    DECLARE @input_left VARCHAR(800)
    DECLARE @delimiter CHAR(1)
    select @delimiter = ','
    DECLARE @in VARCHAR(800)
    DECLARE @list VARCHAR(800)
    declare @list2 VARCHAR(800)


    SET @input = 'AWCA,GCS,IHP,A etna'
    select @c_input = (select dbo.Fx_CharCoun t(@delimiter,@i nput))
    set @c_input = @c_input + 1
    while @c_input > 0
    BEGIN
    select @i_input = charindex(@Deli miter,@input)
    if @i_input != 0
    BEGIN
    select @input_left = left(@input, @i_input - 1)
    END
    else
    select @input_left = @input

    select @in = '''' + @input_left + ''''
    select @list = ISNULL(@list + ',', '') + @in

    select @input = right(@input ,(len(@input) - @i_input))
    SET @c_input = @c_input -1
    if @c_input = 0 or @input = @input_left
    break
    end

    PRINT @list

    EXECUTE ('SELECT Label FROM repricingsystem type WHERE Label Not IN (' + @list + ')')END
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by lazydev
    Here's my code just redirect the output to a variable or out statement
    any suggestions

    alter proc r (@id INT)
    as
    BEGIN

    DECLARE @input VARCHAR(800)
    DECLARE @c_input INT
    DECLARE @i_Input INT
    DECLARE @input_left VARCHAR(800)
    DECLARE @delimiter CHAR(1)
    select @delimiter = ','
    DECLARE @in VARCHAR(800)
    DECLARE @list VARCHAR(800)
    declare @list2 VARCHAR(800)


    SET @input = 'AWCA,GCS,IHP,A etna'
    select @c_input = (select dbo.Fx_CharCoun t(@delimiter,@i nput))
    set @c_input = @c_input + 1
    while @c_input > 0
    BEGIN
    select @i_input = charindex(@Deli miter,@input)
    if @i_input != 0
    BEGIN
    select @input_left = left(@input, @i_input - 1)
    END
    else
    select @input_left = @input

    select @in = '''' + @input_left + ''''
    select @list = ISNULL(@list + ',', '') + @in

    select @input = right(@input ,(len(@input) - @i_input))
    SET @c_input = @c_input -1
    if @c_input = 0 or @input = @input_left
    break
    end

    PRINT @list

    EXECUTE ('SELECT Label FROM repricingsystem type WHERE Label Not IN (' + @list + ')')END
    Sorry I didn't get your question. Kindly tag your code with as well. Indention will also help.

    I can help you more if I can see some sample data and what your desired output.

    -- CK

    Comment

    • lazydev
      New Member
      • Mar 2008
      • 2

      #3
      my actual task is like this
      My input is a list of values seperated by commas
      now my output should be list of values not in the table joined by comma

      eg : if my table consists of list of all databases like

      db2
      oracle,
      sybase,
      mssql,
      mysql,



      myinput would be like this db2,sybase,orac le
      my output should be mssql,mysql
      how to get that
      ?

      Comment

      Working...