I was working on this earlier in the week, and while trying to create a view from an SP, it was suggested that I create a UDF and call that function from inside of a view. I am stuck, since I am not sure what I am doing. Do I need to create 2 functions to get this to run?
Here is the code that will get what I need into the view. But I don't know how to deal with that while exists line.
Any help would be appreciated.
Here is the code that will get what I need into the view. But I don't know how to deal with that while exists line.
Any help would be appreciated.
Code:
Create Table #h2uHealthTopicIND (HealthTopic varchar(600),
ind_cst_key varchar (38))
Create Table #h2uHealthDescripIND (HealthDescrip varchar(255),
ind_cst_key varchar (38))
Insert Into #h2uHealthTopicIND
Select LTrim(Rtrim(ind_health_topic_of_interest_ext)),
ind_cst_key
From co_individual_ext
JOIN co_individual ON ind_cst_key = ind_cst_key_ext
WHERE ind_health_topic_of_interest_ext IS NOT NULL
While Exists(Select * From #h2uHealthTopicIND Where CharIndex(',', HealthTopic) > 0)
Begin
Insert Into #h2uHealthDescripIND(HealthDescrip,ind_cst_key)
Select Left(HealthTopic, CharIndex(',', HealthTopic)-1),
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,ind_cst_key)
Select REPLACE(HealthTopic,',',''),ind_cst_key
From #h2uHealthTopicIND
Select HealthDescrip,
ind_cst_key
From #h2uHealthDescripIND
DROP TABLE #h2uHealthTopicIND
DROP TABLE #h2uHealthDescripIND
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO