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 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.
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
SQL Server | Other
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 125.7K 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,626 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.