I have two tables:
- Table
Acontains the columnsIDandQuery. - Table
Bcontains the columnsID,ValueandCategory.
In every row of table A (without any exceptions) the column Query contains an SQL query as nvarchar, which looks something like SELECT * FROM B WHERE Category = 1.
I cannot figure out, how i can execute all Queries of table A and merge those results and return them (inside a select statement).
I already tried to iterate through all rows in table A, inserting the results of EXEC(Query) into a temporary table #C and finally execute SELECT * FROM #C. But i was not successful with this solution.
EDIT
Just for clarification: The columns and their data types of the resultsets of the queries - stored in table A - are identical. Table B just has a column with datatype [timestamp]. The exception i receive is:
Cannot insert an explicit value into a timestamp column. Use INSERT with a column list to exclude the timestamp column, or insert a DEFAULT into the timestamp column