|
-
SQL Update Issue
I'm trying to run an update statement to update the exp_date column in the COURSES table based on the exp_date in the NEW_COURSES table. I only want to update the column if the the exp_date in the two tables don't match. The problem is that I keep getting an error saying I can't update the exp_date to null (exp_date is a non-nullable column). I've checked several times that neither tables contain null exp_dates.
The compound key on both tables is user_id, course_id, and start_date.
Here's the update statement I'm using:
UPDATE COURSES
SET EXP_DATE = (SELECT A.EXP_DATE FROM NEW_COURSES A
WHERE A.USER_ID = COURSES.USER_ID AND A.COURSE_ID = COURSES.COURSE_ID AND A.START_DATE = COURSES.START_DATE)
WHERE EXISTS (SELECT A.EXP_DATE FROM NEW_COURSES A
WHERE A.USER_ID = COURSES.USER_ID AND A.COURSE_ID = COURSES.COURSE_ID AND A.START_DATE = COURSES.START_DATE AND A.EXP_DATE != COURSES.EXP_DATE);
Does anyone have an idea of what I'm doing wrong?? Let me know if you need more information.
Thanks in advance for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|