Home > database >  Questions about the dynamically generated table variables
Questions about the dynamically generated table variables

Time:10-24

Background:
1, defines a table variable, storage to create all the column of the table variable:
 
Declare @ strlist table (id int identity (1, 1), the strid varchar (15))



2, through the loop to create a table variable structure @ Noteinf_list:


Requirements:
I just want to now how to call this table variables in the dynamic SQL, there is no direct select @ Noteinf_list this variable names,

In the dynamic SQL statement (inner), call it, is how to implement?

CodePudding user response:

I changed idea, generated in the dynamic SQL script like this:
 
Declare @ Noteinf_list table (
Notena varchar (30),
[2020-01] int,
In 2020-02 int,
[2020-03] int,
The 2020-04 int,
2020-05 int,
[2020-06] int,
The 2020-07 int,
[in the 2020-08] int,
The 2020-09 int,
[2020-10] int
)

Insert the @ Noteinf_list
Select * from (
Select [notena]
, [mCour]
, [TolVal]
The from [Noteinfdtl]
) p pivot (
Max ([TolVal]) for [mCour] in [[2020-01], [2020-02], [2020-03], [2020-04], [2020-05], [2020-06], [2020-07], [2020-08], [2020-09], [2020-10])
) PVT

So can generate results, not desirable variables data (outer), which make a ghost
  • Related