B
B
bsd92015-12-13 12:47:12
SQL
bsd9, 2015-12-13 12:47:12

Is it possible to write an UPDATE that will update the id values?

There is a query like this:
SELECT SCHED.mList_id, ml.id, MD.mList_id, SM.mList_id
FROM [TEST].[dbo].[PATP_Schedule] AS SCHED
INNER JOIN TEST..PATP_MarshrutList AS ML
ON SCHED.mList_id = ML. id
INNER JOIN TEST..PATP_MarshrutData AS MD
ON MD.mList_id = ML.id
INNER JOIN [TEST].[dbo].[PATP_SubMarshrut] AS SM
ON ML.id = SM.mList_id
prints table ID values. Help write an UPDATE that will update them starting at 2000 for example. Thanks in advance.1451f2c0c07a440ca1d19a5b327cdfd2.PNG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aleksey Ratnikov, 2015-12-13
@mahoho

CTE to help you:

WITH cteName as (
SELECT SCHED.mList_id, ml.id, MD.mList_id, SM.mList_id
FROM [TEST].[dbo].[PATP_Schedule] AS SCHED
INNER JOIN TEST..PATP_MarshrutList AS ML
ON SCHED.mList_id = ML.id
INNER JOIN TEST..PATP_MarshrutData AS MD
ON MD.mList_id = ML.id
INNER JOIN [TEST].[dbo].[PATP_SubMarshrut] AS SM
ON ML.id = SM.mList_id
)

UPDATE cteName set mList_id =  <someValue>;

And yes, you can update only one table. If you need to update all fields in general that are selected there, issue SELECT as VIEW and write an INSTEAD OF INSERT trigger for it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question