Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help with multiselect insert

Author  Topic 

lwhalen618
Starting Member

4 Posts

Posted - 2008-05-14 : 23:27:56
How do you insert a row when you have multiple values from a multiselect listbox? I have two tables,

TableParent (ASSIGNNUM (PK), DESC, STARTDATE)
TableChild (ASSIGNNUM (FK), EMPLOYEENUM)

Each assignment (ASSIGNNUM) could have multiple employees (EMPLOYEENUM)connected with it. The user is choosing the employees from a multiselect listbox. I assume that I need to somehow loop through the multiple values to create the INSERT statement but don't know how to do that.


Sample data:

TableParent
1....First Assignment....05/01/2008
2....Second Assignment...05/03/2008
3....Third Assignment....05/07/2008

TableChild
1....55342
2....33456
2....52343
3....35225
3....45121
3....11553

Any suggestions would be appreciated!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-14 : 23:54:43
[code]INSERT INTO TableChild
SELECT t.ASSIGNNUM,
FROM TableParent t
CROSS APPLY dbo.fnParseList(',', @EmpList)[/code]


Where @EmpList is parameter which contains comma seperated value passed from multiselect.

The function dbo.fnParseList parses the comma seperated value and returns a table of empids. Serach for this function within this forum and create it in your db first before using this.
Go to Top of Page
   

- Advertisement -