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 2008 Forums
 Transact-SQL (2008)
 Comma delimited string passed to storedproc

Author  Topic 

scripter
Starting Member

49 Posts

Posted - 2010-06-05 : 14:25:01
I have a table that looks something similar to

ID | ZipCode | CompanyID
1 33710 2
2 33712 2
3 33713 2
4 33714 2


CREATE PROCEDURE [dbo].[InsertUpdateContractor]
@ZipCodes varchar(4000)
AS
Begin
INSERT INTO dbo.ServiceAreas
(
ZipCode,
CompanyID
}
VALUES
(
@ZipCode,
@CompanyID
)

The variable of @ZipCodes should look something like whats below
@ZipCodes = "33710,33756,32385,33955"
How do I Insert just one of those Zipcodes at a time. So I would essentially have 4 more rows of zipcodes ?

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2010-06-05 : 23:58:00
you need a table valued function to split on the commas. there are several here: http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648


elsasoft.org
Go to Top of Page
   

- Advertisement -