What i wannt is something like this:
SELECT * FROM [dbo].[UNIONTABLE1]
UNION
SELECT * FROM [dbo].[UNIONTABLE2]
AS RESULTUNION;
DELETE FROM [dbo].[ResultTestTable];
INSERT INTO [dbo].[ResultTestTable]
(
test2
,test3
,test4
,test5
,test6
,test7
)
VALUES
(
RESULTUNION.LT_ALL_TAB_NAME
,RESULTUNION.LT_SCH_KL_RED_GASDRUCK
,RESULTUNION.LT_EINST_NOR_ZEIT + RESULTUNION.LT_EINST_NOR_AUSBLASZEIT
,RESULTUNION.LT_EINST_SAN_ZEIT + RESULTUNION.LT_EINST_SAN_AUSBLASZEIT
,RESULTUNION.LT_EINST_NOR_ZEIT_PCS + RESULTUNION.LT_EINST_NOR_AUSBLASZEIT_PCS
,RESULTUNION.LT_EINST_SAN_ZEIT_PCS + RESULTUNION.LT_EINST_SAN_AUSBLASZEIT_PCS
);
I wannt to fill the ResultTestTable with all rows of the RESULTUNION table but only with specific columns of the RESULTUNION table.
And additionally i wannt to add two column datas of the RESULTUNION table and map it to one column in the ResultTestTable.
The added values are floats.
I m working with Microsoft SQL Server Management Studio.
The statemant above does not work, which is obvious, but i dont know how to do it right.
If I execute the statement above, i get the following error:
Msg 4104, Level 16, State 1, Procedure test_storedProcedure, Line 31
The multi-part identifier “RESULTUNION.LT_ALL_TAB_NAME” could not be bound.
I assume i have to do something like a for-loop but than i dont know how much rows the RESULTUNION table has to loop over.
Does anybody has an idea.
Thanx
First of all, never use “SELECT *” in your SQL, always specify the column names. Once you take that into account, it becomes easier to see the solution. Here it is:
Obviously, if the columns of the two tables have different names, you’ll have to amend the query accordingly.