You must Sign In to post a response.
  • Category: SQL Server

    Insert query from one table to another table

    I have two table like below
    Table 1
    uid hour
    1 8am
    2 9am
    3 10am
    4 10am
    5 11am
    6 11am
    7 11am

    Table2 --I need a query to insert value from above table like below value.
    h8am h9am h10am h11am 12am..
    1 1 2 3 0
    thanks
  • #761637
    Hi Sankar.

    What is your requirement? I didn't get what you are asking about.
    Can you elaborate so that we can provide you the exact query.

    Regards

    Sridhar Thota.
    If you learn't from defeat..
    You haven't really lost..

    Sridhar Thota.
    Editor: DNS Forum.

  • #761645
    Following is your required query. Enjoy :)


    INSERT INTO [dbo].[Table_2]
    ([Col1]
    ,[Col2])
    ( SELECT count(*) as Col1, hour
    FROM [Test11].[dbo].[Table_1] group by hour)

    By Nathan
    Direction is important than speed

  • #761653
    Hi,

    What about Table2 columns...?

    For example if Table1 Contains n no of rows under column hours, then how do you insert into Table2.?

    Please elaborate your requirement and share your table structure..

    Hope you got my point...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


Sign In to post your comments