Monday, May 02, 2005

How to insert multiple values using single Query

Today i happend to answer this question in a users group, I felt to share the method I used
in many occassions.
EG: If you have a user Service selection interface where customer can subscribe for more than
one Service at a time. You may be using a set of a check boxes or a multi-selection listbox. The best way is to can create a coma seperated list from the check list(say ServiceID),so that you can use a Query something like this :

"INSERT INTO Customer-Services "
& " SELECT " & CustmerID & " , ServicesID "
& " FROM Services WHERE ServicesID IN (" & ComaSerpatedList & ")"

No comments: