I am trying to get to the Customer table from data in the SiteConfiguration table.
I am getting the data and setting it to @AdditionalVoteViewers
, which would be a string of emails address. I then split the string and insert the results into a temp table.
At that point, I will join the temp table with the Customer table to return the CustomerId.
I just want to see if there is a better way to do this.
Data In SiteConfiguration Table
[email protected];[email protected]
Data in Customer table
[email protected] 1
[email protected] 2
Code:
declare @AdditionalVoteViewers VARCHAR(100)
Select @AdditionalVoteViewers =
(
SELECT [Value] FROM [SiteConfiguration]
where Name = 'AdditionalVoteViewers'
)
print @AdditionalVoteViewers
--CREATE TABLE #TempAdditionalVoteViewers(email varchar(MAX) )
select * into #TempAdditionalVoteViewers
from [dbo].[Split] (@AdditionalVoteViewers,';')
--select * from #TempAdditionalVoteViewers
select [CustomerId] into #TempAdditionalVoteViewersId
from [dbo].[Customer] c
join #TempAdditionalVoteViewers t on c.Email = t.val
select * from #TempAdditionalVoteViewersId