ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 4th, 2005, 11:13 AM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
CFQUERY - Missing Operator

Can anyone help me out with this statement. I am trying to insert data into table a from table b where table a and table b have three fields which are the same, and I keep getting a missing operator error. Is this even possible, because when I was searching on this topic I noticed a lot of people discussing the use of a temp table. I am using MS access and CF 6.1MX, I tried to run this in the SQL view query in access and got the same error. I posted this on the SQL forum, but wanted to post here as well to see if anyone had come across anything like this before. Thanks in advance.

<cfquery name="updatetest" datasource="ptnadmin">
Update test
SET officeaddress = b.address,
officeaddress2 = b.address2,
officecity = b.city,
officestate = b.state,
officezip = b.zip,
officephone = b.phone,
me = b.me,
ims = b.ims
FROM test a
INNER JOIN A751P b on b.firstname = a.firstname AND b.lastname = a.lastname AND b.state = a.state
</cfquery>

Reply With Quote
  #2  
Old May 4th, 2005, 12:22 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
Your query is wrong.

UPDATE [table] SET [field]=[value] WHERE [field]=[value]
or:
UPDATE [table1] SET [field]=(SELECT [field] FROM [table2] WHERE [field]=[value]) WHERE [field]=[value]

Read over some SQL tutorials on subqueries.

Reply With Quote
  #3  
Old May 4th, 2005, 02:01 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
But that would only update one field. I need to update multiple fields.

I need to take info from table1.a and put it into table2.a, take info from table1.b and put it into table2.b, if table1.c and table2.c are equal.

Reply With Quote
  #4  
Old May 4th, 2005, 02:48 PM
bocmaxima's Avatar
bocmaxima bocmaxima is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Aug 2004
Location: Tucson, Sonora
Posts: 1,322 bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level)bocmaxima User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 17 h 46 m 5 sec
Reputation Power: 23
Send a message via AIM to bocmaxima
Are you inserting data or are you updating it, i.e. - are there already records in the table that you wish to update?

If not, and you are indeed inserting it, then this is the syntax:
INSERT INTO table1 (field1,field2,field3)
(SELECT field1,field2,field3 FROM table2)

This generally works with all SQL versions.
It is very important that both lists of fields correspond to each other.

Hope that helps.

Reply With Quote
  #5  
Old May 4th, 2005, 03:28 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
Ok so I updated it to this and got a syntax error, What am I missing here? Thanks for the help by the way

<cfquery name="updatepcptest" datasource="ptnadmin">
INSERT INTO PCPtest(officeaddress, officeaddress2, officecity, officestate,officezip, officephone, me, ims)
(SELECT address, address2, city, state, zip, phone, me, ims
FROM A751P)
WHERE A751P.firstname = PCPtest.firstname AND A751P.lastname = PCPtest.lastname AND A7514.state = PCPtest.state)
</cfquery>

Reply With Quote
  #6  
Old May 5th, 2005, 08:01 AM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 23 m 47 sec
Reputation Power: 4
You may want to double check on the second table information on your update--the 'FROM' and the 'INNER JOIN.'

Of course, if you can copy in your error, that may help with your question as well.

Reply With Quote
  #7  
Old May 5th, 2005, 11:54 AM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
After reading up on this, I have the following in the CF query. I don't get any errors, however it sets new records into the database at the bottom of the table instead of inserting the values into the correct fields. I think this has something to do with appending, but am not sure. I don't want to insert new fields, but I want to insert the data from one table into the correct fields in another. Is this were I need to back to trying to update instead of insert, and if so how in the world. I am so confused.

INSERT INTO PCPtest ( officeaddress, officecity, officestate, officezip, officephone, me, ims )
SELECT address, city, state, zip, phone, me, ims
FROM A751P
WHERE exists (SELECT officeaddress, officecity, officestate, officezip, officephone, me, ims FROM PCPtest WHERE A751P.firstname = PCPtest.firstname AND A751P.lastname = PCPtest.lastname AND A751P.state = PCPtest.homestate)

Reply With Quote
  #8  
Old May 5th, 2005, 12:51 PM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 23 m 47 sec
Reputation Power: 4
Insert adds new fields to the table and update edits the information in a specific row determined by the where statement (i.e. where ID = 5 or where lastname = 'smith'). Since you are trying to edit/append data, you would probably need to use update.

Reply With Quote
  #9  
Old May 5th, 2005, 03:23 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
Wouldn't this do the trick? Why am I getting a syntax error in the UPDATE statement?

UPDATE PCPtest
SET("officeaddress", "officecity", "officestate", "officezip", "officephone", "me", "ims") = ([A751P.address], [A751P.city], [A751P.state], [A751P.zip], [A751P.phone], [A751P.me], [A751P.ims])
WHERE exists (SELECT address, city, state, zip, phone, me, ims FROM A751P WHERE A751P.firstname = PCPtest.firstname AND A751P.lastname = PCPtest.lastname AND A751P.state = PCPtest.homestate);

Reply With Quote
  #10  
Old May 5th, 2005, 04:04 PM
erikd erikd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: NYC
Posts: 81 erikd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 19 sec
Reputation Power: 5
ok so I figured out how to do this pretty easily for one field per query

UPDATE PCPtest, A751P SET PCPtest.me = A751P.me
WHERE A751P.firstname=PCPtest.firstname And A751P.lastname=PCPtest.lastname And A751P.state=PCPtest.homestate;

Anyone have any ideas on how to do this for multiple fields at the same time? Thanks for the help

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > CFQUERY - Missing Operator


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway