sql server - Change T-SQL Query Using an INSERT with Table Valued Function into a View Instead -


the query concerns 1 table holding contacts data. table valued function used return "status" each contact.

the insert statement grabs unique key contacts table , loads variable called @filteredidlist. joined contacts table , again table-valued function passing variable @filteredidlist it.

i have simplified example down show how i'm returning status. needs changed view instead:

declare @filteredidlist idlist; insert @filteredidlist select contactid contacts  select         contacts.contactid,         contact_status    contacts        inner join @filteredidlist [idlist] on contacts.contactid = [idlist].[id]        inner join tvfcontact_status(@filteredidlist) contact_status        on [idlist].[id] = contact_status.contactid 

i have tried creating cte inside view couldn't figure out.

i believe cte looking be.

;with nameofcte (idlist) (   select contactid contacts ) 

then use nameofcte in join statement.

i not use ctes everyday give post on simple talk read refresh myself on them before using them. https://www.simple-talk.com/sql/t-sql-programming/sql-server-cte-basics/


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -