Forum Discussion

Dhakshina25's avatar
Dhakshina25
Copper Contributor
Sep 13, 2022

How to pass multiple values into single string in Store

Hi All,

 

I am passing a list of string into my stored procedure as a single value 

For eg: my procedure name is fetch_value

It has single parameter called product.      

Alter procedure fetch _value()

@product varchar(Max)

As 

Set @product  = substring ((

Select distinct ','+ product from main_table)T1 

Order by 1

For xml path ('')),2,2000);

 

Set @products = N''''+ Replace(@product,N',N''',''')+N'''')

 

Print @products

So the above stored procedure returns the list of separeted by comma in my main table for eg. 'pen,pencil,eraser'.  I have a product called 1,4-diode so here in this product,there is comma in middle and it is treating as separate value and I want to have it has same value,can someone please help me in solving this case?

Thanks in Advance 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2 Replies

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    Dhakshina25 , and how do you prefered to get it solve?

    One way is to replace the comma with an other character, like the semicolon:

     

    Set @product  = substring ((
        Select distinct ','+ REPLACE(product, ',', ';') 
        from main_table) T1 
        Order by 1
        For xml path ('')),2,2000);
    • Kalai_harini's avatar
      Kalai_harini
      Copper Contributor
      Thanks for your valuable time
      I exactly need(,) in the middle because my database value has comma in it, if I replace with semicolon it will not give any results

Resources