I have a table in that table has 1 column(Cols) and it has 2 Records see below

I have another table and it has 4 columns see below

I want to insert first table 2 columns into 2nd table FieldName column
How to do that?
I have a table in that table has 1 column(Cols) and it has 2 Records see below

I have another table and it has 4 columns see below

I want to insert first table 2 columns into 2nd table FieldName column
How to do that?
Your question is anything but clear. For these type of questions, we recommend that you post CREATE TABLE statements for your tables and INSERT statements with test data, and the expected result of the test data. The test data set should preferably be big enough to illustrate all angles of the problem. This makes it easy to copy and paste into a query window to develop a tested solution.
It also helps if you give a short description of the business rules that explains why you want that particular result.
Finally, include the output from "SELECT @@version".
My Question is
For example i have two tables table-1 and table-2.
I have created a Dynamic Stored procedure with 2 parameters that takes two table names.
.
That stored procedure code copies the whatever i added or deleted rows in table-1 it will add all those column names into table-2
If i add or delete column(s) in table-1 after that i execute that Stored procedure it will add or delete the rows into table-2.
Now i want to record all activities like
TableName(Which table is effected after execute Stored procedure),
FieldName(Which is nothing but column name of added in table-2),
OperationType(Added/Deleted message),
Date(Date of execution).
This is the problem
I understand even less now. As a starting point, could you post a script with that stored procedure an example of it in action, so that we understand what is is doing?
I would also be curious with the ultimate purpose of this procedure. Passing table names as parameter isn't exactly a vanilla operation.
Maybe you need something like this:
insert AnotherTable (TableName, FieldName, OperationType, [Date])
select @FinalTable, Cols, 'Added', getutcdate()
from #AddedColumns
union all
select @FinalTable, Cols, 'Deleted', getutcdate()
from #DeletedColumns
Hi @MadhusudanReddyMandala-4641,
Welcome to the microsoft TSQL Q&A forum!
Could you please validate all the answers so far and provide any update?
If all of them are not working or helpful, please provide more sample data or details about your issue.
Please remember to accept the answers if they helped. Your action would be helpful to other users who encounter the same issue and read this thread.
Thank you for understanding!
Regards
Echo
20 people are following this question.