Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update field with Select and Join
Message
 
 
To
26/02/2019 17:36:36
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01666758
Message ID:
01666764
Views:
38
>>Hi,
>>
>>I am always concerned when I need to create a SQL Update evolving SQL Select with join.
>>
>>Here is a pseudo syntax
>>
>>
>>
>>*--  I need to update the column eqpmsch.month_week and set it to 1 where it is greater than 1.
>>
>>*-- The following SQL Select will select the rows I need to update. 
>>select eqpmsch.month_week  from eqpmsch join pm_task on pm_task.task_no = eqpmsch.task_no 
>>where pm_task.freq = 12 and eqpmsch.month_week > 1
>>
>>*-- This is my attempt at creating a SQL Update
>>update eqpmsch set month_week = 1 where select eqpmsch.month_week  from eqpmsch join pm_task on 
>>pm_task.task_no = eqpmsch.task_no where pm_task.freq = 12 and eqpmsch.month_week > 1
>>
>>
>>
>>I get error near the key word SELECT (in the SQL Update above). How do I change it?
>>
>>TIA
>>
>>UPDATE. The following syntax does not have an error:
>>
>>update eqpmsch set month_week = 1 from eqpmsch join pm_task on 
>>pm_task.task_no = eqpmsch.task_no where pm_task.freq = 12 and eqpmsch.month_week > 1
>>
>>
>>I am still not 100% sure if the above is the correct syntax. Please let me know.
>
>It is correct.

Thank you!
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform