+ Reply to Thread
Results 1 to 3 of 3

Thread: Sql help plz

  1. #1
    amjames is offline x10Hosting Member amjames is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    7

    Sql help plz

    I have a few sql queries that select data from a table on 1 database and stores it in a table on a different database. My problem comes when the table on the second database has an additional column which i want to add text dependant on what query is run. i.e. the name of the query.

    example query (Where columns on both database tables are the same)

    insert into testtable (col1,col2,col3)
    select col_a,col_b,col_c
    from anothertest.testtable
    where col_a = 'test';

    How do I declare say col4 = 'thisQuery' in the above statement?

    hope this makes sense. :happysad:

  2. #2
    gomarc's Avatar
    gomarc is offline x10 Elder gomarc is an unknown quantity at this point
    Join Date
    Oct 2007
    Location
    USA
    Posts
    511

    Re: Sql help plz

    If you need to add a column to a table, in the SQL query you can use:

    Code:
    ALTER  TABLE  `testtable`  ADD  'col4` VARCHAR( 40  )  NOT  NULL ;

  3. #3
    amjames is offline x10Hosting Member amjames is an unknown quantity at this point
    Join Date
    Jan 2009
    Posts
    7

    Re: Sql help plz

    The 4th column already exists I just need to fill it depending on what query is run. I need to declare it but im having a mental block as everything I try seems to bring back an error saying syntax is wrong

    for example - this does not work
    Code:
    insert into testtable (col1,col2,col3,col4)
    set col4 = 'thisQuery'
    select col_a,col_b,col_c
    from anothertest.testtable
    where col_a = 'test';

+ Reply to Thread

Similar Threads

  1. Mi base de datos SQL fue borrada
    By yulifan in forum Soporte
    Replies: 3
    Last Post: 08-28-2008, 11:22 AM
  2. sql database does not restore
    By softwork in forum Free Hosting
    Replies: 3
    Last Post: 05-20-2008, 06:47 AM
  3. Cannot upload SQL Data
    By pasacom in forum Free Hosting
    Replies: 5
    Last Post: 02-25-2008, 11:24 PM
  4. Sql?
    By SLIForum in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 12-03-2007, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers