-2

I have an arraylist contains Id, ListId's values Listid's is a string contains multiple values with separated by comma like (101, 10,11,12,13). I want store this values into my table. How would i achieve this.

insert into CompanyBillableAsset(Id, ListId)
     values(@Id, set @listId = select ListId from List where ListId in (select SplitValue from dbo.xf_StrSplit(@str, ',')))
  • In what language? What is the table schema? What have you tried, and why didn't it work? – Barmar Jul 20 '13 at 05:08
  • Please post you code Snippet you wrote – Jayesh Jul 20 '13 at 05:09
  • 1
    possible duplicate of [Split string in SQL](http://stackoverflow.com/questions/2647/split-string-in-sql). Please do a basic search before posting a new question here. I found many answers using `[sql-server] split string` in a search here. – Ken White Jul 20 '13 at 05:16
  • @KenWhite As I understand it, the question is not a duplicate, since the mentioned function `xf_StrSplit` seems to exist already. I'd assume it's a problem with the handling of the insert. – bummi Jul 20 '13 at 07:02

1 Answers1

0

With the assumption your dbo.xf_StrSplit is working, your INSERT could look like:

INSERT into CompanyBillableAsset (Id, ListId)
SELECT @Id,ListId 
FROM List 
WHERE ListId in (select SplitValue from dbo.xf_StrSplit(@str, ','))
bummi
  • 27,123
  • 14
  • 62
  • 101