insert into Select

  • i have Three tables

    First table

    ID AccountNo AcctState

    1 399009 TX

    2 090900 CA

    3 090900 NY

    Second table

    ID ActiveFlag Hcode FirstName Lastname

    1 True AAnkj aaaaa bbbb

    2 False AAnkj kjkjkk kjkjkk

    3 True bbkkh kjkfkj ieurhk

    Third table output should be

    IDAccountNo AcctState FirstName Lastname

    1 399009 TX aaaaa bbbb

    2 090900 CA

    3 090900 NY

    i am trying to write an insertinto select statement with join but not sure how to derive the third table output

    Final table should have all the row from the first table but Firstname and lastname column should be blank incase of if the activeflag = false or HCode <> AAnkj

    Please help me on this how to write to insert blank for firstname and lastname column

  • I hate to say this nth time over the past week, Post the DDL Scripts for your tables and some insert scripts that helps us to setup the same data at our end, instead of we building it everything at our server.

    Hence my answer would not a script of what you need , rather, I shall say what to do and you try doing it.

    Use a Temp table (In the Structure as you want here in your case the output), and Insert into that table, the ID and AccountNo and NULLs in the FirstName and LastName Column, and update that temp table with Data from the Table2


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply