Answer the question
In order to leave comments, you need to log in
How to put exec in a table function?
There are tables in the database with numbering (for example, clients_1, clients_2), the number changes every month. I want to make a table function that would return certain clients, giving the input just the number 1/2 ...
Inside the function, using dynamic sql, a query is formed with the name of the desired table, for example:
declare @tableNumber varchar(100) -- на входе подаем 1/2/3...
declare @sql varchar(100)
set @sql = '
select *
into #tempTable
from dbo.clients_' + @tableNumber
exec(@sql)
return #tempTable
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question