sql server - Case statement that does nothing if When is not true -


I am trying to update a table that contains a specific account id, which contains more than once For example, I have Account ID 1 in Table B and 1 in Account A, which is Eight 1, which is 5 times.

Therefore, I am updating in a row with all the data in a row that all the data in that one row

example:

Table A has multiple records per account ID

  accountID site hard soft 1 12 20 0 1 13 30 10 1 14 40 0 ​​ 

Update me to Table B , Which only has an account ID and no other data and looks like this:

  accountID site12_hard site12_soft site13_hard site13_soft site14_hard site14_soft 1  

So I linked the account ID and made a case statement for all areas. This way:

  update table b set site12_hard = case when the site = 12 then hard and end, site12_soft = case when the site = 12 then the soft and 0 end, the table contains an internal table This is not working as it is, because many links on the account ID are the case statement to evaluate every incident of that account. If the site is 12_Hard But it can be updated properly, but when it comes back to account ID = 1 To show it is not = 12, so it is updated to zero.  

I would like a way to make a case statement if nothing is "if" right or I need a completely different method to update this table.

I just created site 12 & amp; 13 should be similar to site 14 . Try ..

  UPDATE B SET site12_hard = a.site12_hard, site12_soft = a.site12_soft, site13_hard = a.site13_hard, site 13_soft = a.site13_soft table B b inner (SELECT accountID, The site is 12_However, Max (in case [site] = 12 then soft end) Site 12_soft, max (in case [site] = 13 difficult in the case] Site 13_Hard, in max (case when [site] = 12th strict END) site 12_Hard, Max (in case when a [site] = 13th soft EDD site 13_Soft table A group bye ID) Account id = baccountID  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -