none
Need a UPDATE Statement

    Question

  • hi friends

    I have two tables:

    Table A:

    Column1      Column2

    NULL A
    NULL B
    NULL C

    Table B:

    Column1

    1
    2
    3

    How to write a query to update table A to below model:

    TableA:\

    Column1 Column2

    1    A
    1    B
    1    C
    2    A
    2    B
    2    C
    3    A
    3    B
    3    C


    Royal Thomas

    Wednesday, September 25, 2013 8:11 PM

Answers

  • create table Table_A (Column1 int,     Column2  varchar(50))
    Insert into Table_A (Column2) values('A'),('B'),('C')
    create table Table_B (Column1 int )
    Insert into Table_B (Column1) values(1),(2),(3)
    --Select b.Column1, a.Column2 Into NewTable_A from Table_A a, Table_B b
    --Select * from NewTable_A
    ----drop table NewTable_A
    Insert into Table_A(Column1,Column2)
    Select b.Column1, a.Column2  from Table_A a, Table_B b
    Delete From Table_A WHERE Column1 IS NULL
    Select * From Table_A
    Order By Column1
    drop table Table_A
    drop table Table_B

    • Marked as answer by Royal Thomas Wednesday, September 25, 2013 8:31 PM
    Wednesday, September 25, 2013 8:23 PM