Sample Header Ad - 728x90

Temp tables streamline query

3 votes
1 answer
144 views
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
-none
123@123.com;456@456.com
Data in *Customer* table
-none
123@123.com 1
456@456.com 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
Asked by Jefferson (111 rep)
Oct 25, 2024, 05:12 PM
Last activity: Oct 27, 2024, 08:00 AM