Thanks. Here is the SP that I had planned to be used. I have another that runs with variables, since I was going to just put this into a report. The application is a .net, with SQL back end. Inside the application is a way to use "list tables" and have the end user run GUI type query's and create mailing labels and email list with out having to export a file.
Here is the code that I wanted to use for the view.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.sp_h2u_health_topics_individual_affiliate
AS
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
Create Table #h2uHealthTopicIND (HealthTopic varchar(600),
chp_code nvarchar(10),
chp_name nvarchar(150),
cst_name_cp nvarchar (150),
cst_eml_address_dn nvarchar(80),
cxa_mailing_label nvarchar (450),
chp_cst_key varchar (38),
ind_cst_key varchar(38))
Create Table #h2uHealthDescripIND (HealthDescrip varchar(255),
chp_code nvarchar(10),
chp_name nvarchar(150),
cst_name_cp nvarchar (150),
cst_eml_address_dn nvarchar(80),
cxa_mailing_label nvarchar (450),
chp_cst_key varchar (38),
ind_cst_key varchar(38))
Insert Into #h2uHealthTopicIND
Select LTrim(Rtrim(ind_health_topic_of_interest_ext)),
chp_code ,
chp_name ,
cst_name_cp ,
cst_eml_address_dn ,
cxa_mailing_label ,
chp_cst_key,
ind_cst_key
From co_individual_ext
JOIN co_individual ON ind_cst_key = ind_cst_key_ext
LEFT JOIN co_customer ON cst_key=ind_cst_key
Left Join mb_membership (nolock)ON mbr_cst_key=cst_key
Left Join co_chapter (NOLOCK) ON chp_cst_key=mbr_chp_cst_key
LEFT JOIN mb_association (NOLOCK) ON asn_key=chp_asn_key
JOIN co_customer_x_address (Nolock)ON cst_cxa_key = cxa_key
LEFT JOIN co_address (NOLOCK) ON adr_key=cxa_adr_key
WHERE ind_health_topic_of_interest_ext IS NOT NULL AND chp_code IS NOT NULL
While Exists(Select * From #h2uHealthTopicIND Where CharIndex(',', HealthTopic) > 0)
Begin
Insert Into #h2uHealthDescripIND(HealthDescrip,chp_code,chp_name,cst_name_cp,cst_eml_address_dn,cxa_mailing_label,chp_cst_key,ind_cst_key)
Select Left(HealthTopic, CharIndex(',', HealthTopic)-1),
chp_code ,
chp_name ,
cst_name_cp ,
cst_eml_address_dn ,
cxa_mailing_label ,
chp_cst_key,
ind_cst_key
From #h2uHealthTopicIND
Where CharIndex(',', HealthTopic) > 0
Update #h2uHealthTopicIND
Set HealthTopic = LTrim(RTrim(Right(HealthTopic, Len(HealthTopic)-CharIndex(',', HealthTopic))))
End
Insert Into #h2uHealthDescripIND(HealthDescrip,chp_code,chp_name,cst_name_cp,cst_eml_address_dn,cxa_mailing_label,chp_cst_key,ind_cst_key)
Select REPLACE(HealthTopic,',',''),chp_code,chp_name,cst_name_cp,cst_eml_address_dn,cxa_mailing_label,
chp_cst_key,ind_cst_key
From #h2uHealthTopicIND
Select s03_health_topic = HealthDescrip,
s03_chp_code = chp_code,
s03_chapter=chp_name,
s03_name =cst_name_cp,
s03_email =cst_eml_address_dn,
s03_mailing_label = cxa_mailing_label,
s03_cst_key = ind_cst_key
From #h2uHealthDescripIND
DROP TABLE #h2uHealthTopicIND
DROP TABLE #h2uHealthDescripIND
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO