Sql help plz

amjames

New Member
Messages
7
Reaction score
0
Points
0
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:
 

gomarc

Member
Messages
516
Reaction score
18
Points
18
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 ;
 

amjames

New Member
Messages
7
Reaction score
0
Points
0
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';
 
Top