MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL 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 June 27th, 2012, 04:43 PM
boulderrr boulderrr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 4 boulderrr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 59 sec
Reputation Power: 0
SQL Code Errors - Update Query with Inner Join (Newb)

Hello and thanks in advance for any help!

I was trying to do some table updating within Access, but the tables I'm dealing with are too large. Because of this, I decided to use MS SQL Server Management Studio so that it could be done using SQL code. I was able to formulate my base table, but forgot to add a particular column, so want to update this table now.

Every table referenced below is contained within my database, which is titled KS_SS_2012.05.31_RMS11_RDM

I have a table called Surge_Levels, which has most of my data. I forgot to include a column called MICROZONE. Using SQL Server Management Studio, I was able to add a new column called MICROZONE to the Surge_Levels table. This column is now in there, but is blank.

I have another table within the database called Expacc_Loc, which has the information I need to update the MICROZONE column in the Surge_Levels table. To update the proper fields, I need to join a field in Surge_Levels called LOCNUM and the same field in Expacc_Loc called LOCNUM.

From there, I simply need it to populate MICROZONE in Surge_Levels from what is in Expacc_Loc based on the LOCNUM field.

To do this, I created what I wanted to do in Access, copied the SQL code over, and then did all the modifications I knew were necessary to make SQL run. It appears I must be missing something though, because it isn't working.

This is what I have:

PHP Code:
 UPDATE [KS_SS_2012.05.31_RMS11_RDM]..Expacc_Loc INNER JOIN [KS_SS_2012.05.31_RMS11_RDM]..Surge_Levels ON [KS_SS_2012.05.31_RMS11_RDM]..Expacc_Loc.LOCNUM = [KS_SS_2012.05.31_RMS11_RDM]..Surge_Levels.LOCNUM 


I am getting an error that says :
Quote:
Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'INNER'.


Under the error list, I have:
Invalid Object Name
Quote:
'KS_SS_2012.05.31_RMS11_RDM..Expacc_Loc'.

Incorrect syntax near 'INNER'.

Incorrect syntax near 'ON'.


I'm a newb to SQL and am sure I'm just overlooking something simple. Thanks again!

Reply With Quote
  #2  
Old June 27th, 2012, 05:06 PM
r937's Avatar
r937 r937 is online now
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,380 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 50 m 26 sec
Reputation Power: 4140
Quote:
Originally Posted by boulderrr
To do this, I created what I wanted to do in Access, copied the SQL code over, and then did all the modifications I knew were necessary to make SQL run. It appears I must be missing something though, because it isn't working.
there are several things at play here

first, you posted in the mysql forum, which is a completely different database system from microsoft sql server

(don't worry, i've moved your thread over to the correct forum)

second, microsoft sql server is different from microsoft access sql, you can't just run the same sql syntax

this is the syntax you want --
Code:
UPDATE [KS_SS_2012.05.31_RMS11_RDM]..Surge_Levels 
   SET microzone = t2.microzone
  FROM [KS_SS_2012.05.31_RMS11_RDM]..Surge_Levels AS t1  
INNER 
  JOIN [KS_SS_2012.05.31_RMS11_RDM]..Expacc_Loc AS t2  
    ON t2.LOCNUM = t1.LOCNUM 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old June 27th, 2012, 05:12 PM
boulderrr boulderrr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 4 boulderrr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 30 m 59 sec
Reputation Power: 0
Quote:
Originally Posted by r937
there are several things at play here

first, you posted in the mysql forum, which is a completely different database system from microsoft sql server

(don't worry, i've moved your thread over to the correct forum)

second, microsoft sql server is different from microsoft access sql, you can't just run the same sql syntax

this is the syntax you want --
Code:
UPDATE [KS_SS_2012.05.31_RMS11_RDM]..Surge_Levels 
   SET microzone = t2.microzone
  FROM [KS_SS_2012.05.31_RMS11_RDM]..Surge_Levels AS t1  
INNER 
  JOIN [KS_SS_2012.05.31_RMS11_RDM]..Expacc_Loc AS t2  
    ON t2.LOCNUM = t1.LOCNUM 


Thanks so much and my apologies for posting in the wrong forum. I wasn't quite sure which one was the proper one.

I did modify the code somewhat from Access prior to putting it into SQL (added bracketed DB name, etc), but it looks like I was a bit too simplistic with the transfer over. When I created the original table using SQL, I was able to mostly just transfer the Access SQL code with only minor modifications such as the aforementioned database name inclusion and the bracketing of names with dots in them. As you can tell, I've not ventured far enough into the wonderful world of SQL. Thanks again for your help!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > SQL Code Errors - Update Query with Inner Join (Newb)

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap