Solved

Assistance with an update statement that requires inner join

Posted on 2013-12-19
3
502 Views
Last Modified: 2014-01-29
I am trying to use the update statement below. I receive an error. I am sure it's syntax.  

Here is the query as I originally run it:
UPDATE  a
SET a.startdate=b.proposed_start_date, 
        a.enddate=b.proposed_end_date
FROM    njobslstasks a INNER JOIN 
        lot_schedule_proposed_changes b ON a.PROGRESS_RECID_IDENT_ = b.progress_id
WHERE   b.bldrcode = 'jima'

Open in new window


Here is how the management studio inside of the query window modifies it:

UPDATE    a
SET              a.startdate = b.proposed_start_date, a.enddate = b.proposed_end_date
FROM         rems.njobslstasks AS a INNER JOIN
                      rems.lot_Schedule_proposed_changes AS b ON a.PROGRESS_RECID_IDENT_ = b.progress_id CROSS JOIN
                      a
WHERE     (b.bldrcode = 'jima')

Open in new window


I attached the error message as a screenshot
error.png
0
Comment
Question by:J C
  • 2
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 39730158
do you get the error if you take out the 'CROSSJOIN a' ?
I don't know why it is being added but it seems to be in error.
Make sure you are using New Query option not Open Table option.

Same sort of problem here :

http://www.experts-exchange.com/Programming/Languages/.NET/Q_22640924.html
0
 

Author Comment

by:J C
ID: 39730223
jacko72,

Arg, I was not using the new query window and once I did it works. Can you tell me what I'd need to do to add the delete statement so that after the statement runs it deletes the records in that table? Thank you for your help
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39730264
I think this will do it, please test before using :
UPDATE  a
SET a.startdate=b.proposed_start_date, 
        a.enddate=b.proposed_end_date
FROM    njobslstasks a INNER JOIN 
        lot_schedule_proposed_changes b ON a.PROGRESS_RECID_IDENT_ = b.progress_id
WHERE   b.bldrcode = 'jima' 
go
Delete b FROM njobslstasks a INNER JOIN
        lot_schedule_proposed_changes b ON a.PROGRESS_RECID_IDENT_ = b.progress_id
WHERE   b.bldrcode = 'jima' 
go

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now