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 2000 Forums
 SQL Server Development (2000)
 email list set-up

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-01-23 : 08:36:33
Brent writes "I am writing an email list in asp. I have 3 db tables, 1 with an email and a unique person id, 1 with a group table and a unique group id, and 1 table linking the 2 in a many to many fashion via the ids. I'm trying to write a stored procedure that will enable me to take 1 email and a comma-delimited list of groupnames, and insert them into the linking table all in 1 sp. is this possible? trying to do the same with deleting? The e-mails and groups already exist, just want to put the 1 email into many of the groups."

ThreePea
Yak Posting Veteran

83 Posts

Posted - 2002-01-23 : 09:59:40
quote:

Brent writes "I am writing an email list in asp. I have 3 db tables, 1 with an email and a unique person id, 1 with a group table and a unique group id, and 1 table linking the 2 in a many to many fashion via the ids. I'm trying to write a stored procedure that will enable me to take 1 email and a comma-delimited list of groupnames, and insert them into the linking table all in 1 sp. is this possible? trying to do the same with deleting? The e-mails and groups already exist, just want to put the 1 email into many of the groups."



I think I understand what you're trying to do. Try something like this for the Insert:


SELECT -- only necessary if delimited list does not end with a comma
@Group_List = @Group_List + ','

CREATE TABLE #t1
(Group_ID VARCHAR(50))

WHILE CHARINDEX(',',@Group_List) > 0
BEGIN
SELECT
@Current_Group = SUBSTRING(@Group_List,1,CHARINDEX(',',@Group_List)-1),
@Group_List = SUBSTRING(@Group_List,CHARINDEX(',',@Group_List)+1,LEN(@Group_List))

INSERT #t1
SELECT Group_ID
FROM Group_Table
WHERE Group_Name = @Current_Group
END

INSERT Linked_Table
SELECT
@Email,
Group_ID
FROM #t1

DROP TABLE #t1



---------------------------------
Jan 22, 1973 - A Day of Disgrace
Go to Top of Page
   

- Advertisement -