sql - Updating a db table based on 2 separate conditions -


I need to update my table (dependency) and set a new column (vid) next to a sequence. The way I can not change the data table, please do not mention to remove the redundant data.

However, where there is a problem in the condition, two situations need to be completed (column provider and original). There is a separate primary key (prikey): Table dependency (table of dependencies) (46), worker provider (46), Vertur Genesis (46) Vranchal Other Data (16) with integer)

The sample data will look like this: -

  (prikey, ORIGID, PROVID, VID) ('AA1', 'C3C87F000001', '23', 1), (' AA2 ',' C3C7F000001 ',' 23 ', 1), (' AA3 ',' C3C 87F000001 ',' 26 ', 2), (' AA 4 ',' C 3 C 87 F 000001 ',' 53 ', 3) (' AA5 ',' A3C 87F 00000 9 ',' 26 ', 4), (' AA 6 ',' A3C 87 F 00000 9 ',' 23 ', 5)  

As the data can be seen from , Can repeat the original and providers (which are really foreign keys) For this example, I have added vid values ​​as they should be. A vid basically identifies a line that provides the same original and .

My question: - What is SQL for updating this table vid = sequence.nextval? Try differentiating (provider)

Try:

  merge into dependent dependency (Select DENSE_RANK () by prikey, ORIGID, PROVID), get rid of prikey dependency (dependency.prikey = SOURCE.prikey) on the source when the matching set dependency update. VID = SOURCE.g  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -