I have the following query...
WITH NoEndJobs AS (
SELECT
CustomerID,
JobType,
Book,
Page,
NextDocBook = LEAD(Job.Book) OVER (PARTITION BY CustomerID, JobType ORDER BY Book, Page),
NextDocPage = LEAD(Job.Page) OVER (PARTITION BY CustomerID, JobType ORDER BY Book, Page)
FROM JobList Job
WHERE EndBook='' OR EndPage=''
)
SELECT
NoEndJobs.CustomerID,
NoEndJobs.JobType,
NoEndJobs.Book,
NoEndJobs.Page,
coalesce(LastJobInfo.Book, '') AS EndBook,
coalesce(LastJobInfo.Page, '') AS EndPage
FROM NoEndJobs
LEFT JOIN
(
SELECT
CustomerID,
JobType,
Book,
Page,
PrevEntry
FROM JobEntries
) NextJobEntry ON
NextJobEntry.CustomerID=NoEndJobs.CustomerID AND
NextJobEntry.JobType=NoEndJobs.JobType AND
NextJobEntry.Book=NoEndJobs.NextDocBook AND
NextJobEntry.Page=NoEndJobs.NextDocPage
LEFT JOIN
(
SELECT
ID,
Book,
Page
FROM JobEntries
) LastJobInfo ON LastJobInfo.ID=NextJobEntry.PrevEntry
ORDER BY
NoEndJobs.CustomerID,
NoEndJobs.JobType,
NoEndJobs.Book,
NoEndJobs.Page;
I want to be able to update a table named JobList
with the resulting SELECT rows.
I would like to update the table based off of the CustomerID, JobType, Book and Page. For example... The first row results from the select might be something like...
So I want to do something like this with the results..
UPDATE JobList
SET JobList.EndBook=RESULTS.EndBook, JobList.EndPage=RESULTS.EndPage
WHERE
JobList.CustomerID=RESULTS.CustomerID AND
JobList.JobType=RESULTS.JobType AND
JobList.Book=RESULTS.Book AND
JobList.Page=RESULTS.Page
If I'm not clear on what I'm trying to do I can go into more detail if requested. Basicly I want to take my results and update the table that matches the data set IF EndBook and EndPage fields are not BLANK ('').
I have tried to do a few different things but always get syntax errors never able to make it work. The query above is solid and works well though!