How to Select Row by Row from a table

Madhusudan Reddy Mandala 1 Reputation point
2021-08-21T10:23:37.357+00:00

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

125154-ta1.png

I have another table and it has 4 columns see below

125177-00.png

I want to insert first table 2 columns into 2nd table FieldName column

How to do that?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,492 questions
SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,057 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,707 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.3K Reputation points
    2021-08-21T16:33:30.763+00:00

    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
    
    1 person found this answer helpful.
    0 comments No comments

  2. EchoLiu-MSFT 14,621 Reputation points
    2021-08-26T08:50:34.043+00:00

    Hi @Madhusudan Reddy Mandala ,

    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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.