Welcome to WebmasterWorld Guest from 18.206.194.83

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Problem with concat on an insert

     
5:04 am on Aug 24, 2005 (gmt 0)

New User

10+ Year Member

joined:Aug 24, 2005
posts:3
votes: 0


I am updating a table, inserting multiple rows from a previous form.
This works and inserts the rows
mysql_select_db($database_zen, $zen);
$query_rsCC = "INSERT INTO tblPackingList (marketwk, crop, out) SELECT tblPackingListOLD.marketwk, tblCrop.crop, tblPackingListOLD.cc AS out FROM tblCrop INNER JOIN tblPackingListOLD ON tblCrop.cropID = tblPackingListOLD.crop WHERE tblPackingListOLD.marketwk=17 AND tblPackingListOLD.cc>0";
$rsCC = mysql_query($query_rsCC, $zen) or die(mysql_error());

However, I also need to insert values that are concatenation. The concat works and creates the value that I need.
SELECT CONCAT("cc",tblPackingListOLD.marketwk, tblCrop.crop) AS pid
FROM tblCrop INNER JOIN tblPackingListOLD ON tblCrop.cropID = tblPackingListOLD.crop

Now I need help incorporating the concat into the insert query so that (pid, marketwk, crop, out) are inserted

Thanks

7:27 am on Aug 24, 2005 (gmt 0)

New User

joined:Feb 2, 2005
posts:24
votes: 0


Should work:

$query_rsCC = "
INSERT INTO tblPackingList (pid, marketwk, crop, out)
SELECT CONCAT("cc",tblPackingListOLD.marketwk, tblCrop.crop) AS pid, tblPackingListOLD.marketwk, tblCrop.crop, tblPackingListOLD.cc AS out
FROM tblCrop INNER JOIN tblPackingListOLD ON tblCrop.cropID = tblPackingListOLD.crop
WHERE tblPackingListOLD.marketwk=17 AND tblPackingListOLD.cc>0";
8:11 am on Aug 24, 2005 (gmt 0)

New User

10+ Year Member

joined:Aug 24, 2005
posts:3
votes: 0


You would think it would work, but it results in

Parse error: parse error, unexpected T_STRING

The two separate pieces work but not when combined :-(.

Any other suggestions would be most appreciated.

8:26 am on Aug 24, 2005 (gmt 0)

New User

joined:Feb 2, 2005
posts:24
votes: 0


Ok, sorry (-; i did not notice the extra quotes in the query. You have to escape them or use single quotes:

$query_rsCC = "
INSERT INTO tblPackingList (pid, marketwk, crop, out)
SELECT CONCAT('cc',tblPackingListOLD.marketwk, tblCrop.crop) AS pid, tblPackingListOLD.marketwk, tblCrop.crop, tblPackingListOLD.cc AS out
FROM tblCrop INNER JOIN tblPackingListOLD ON tblCrop.cropID = tblPackingListOLD.crop
WHERE tblPackingListOLD.marketwk=17 AND tblPackingListOLD.cc>0";
10:35 am on Aug 24, 2005 (gmt 0)

New User

10+ Year Member

joined:Aug 24, 2005
posts:3
votes: 0


DOH! and either did I, boy what a difference a second set of eyes makes.
Thanks!
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members