Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2013
    Posts
    6

    Post Unanswered: Addind a new column using query

    I have table A, i want to make a query for creating table B which will insert some of the columns of Table A and add new columns also ti table B, which are not the part of able A?
    How Can i do it in one query

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You can use:
    Code:
    SELECT TableA.*, Null AS NewColumn1, Null as NewColumn2
    INTO TableB
    FROM TableA;
    Have a nice day!

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    PersoanbllyId' probably have tried
    INSERT INTO....
    but no matter

    ..but it does beg the question why you are copying columns form one table and putting them into another table (presuming thats its a table in the same db). if its going into a tbale in another db then its fine, but duplicating data within the same DB is NEVER a samrt move*



    *unless you have good reasons (usually perfomance or possibly legal / accounting reasons)
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    @healdem: INSERT INTO won't be enough for creating table B in one query, as requested.
    Have a nice day!

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by Sinndho View Post
    @healdem: INSERT INTO won't be enough for creating table B in one query, as requested.
    good point, and well made
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jan 2013
    Posts
    6
    Thanks for the solution, but
    I need datatype as Text not in binary

  7. #7
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Mind to explain?
    Have a nice day!

  8. #8
    Join Date
    Jan 2013
    Posts
    6
    I mean to say, when i run the above query "null as B" it creates column B but the datatype is Binary, where as i need the datatype as Text.

  9. #9
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Then use:
    Code:
    SELECT TableA.*, '' AS NewColumn1, '' as NewColumn2
    INTO TableB
    FROM TableA;
    Note: In '' AS New..., '' are 2 single quote characters ('), not one double quote character (").
    Have a nice day!

  10. #10
    Join Date
    Jan 2013
    Posts
    6
    I Got That Thanks for Response...

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •