Update a group of records with one value in the same group

Ads
 

Update a group of records with one value in the same group

I want to update my table group wise, i have three cases AA,BB,CC , if group of records haveing one AA value in name column then those records NAME column should be update with AA. If group is not having AA value second priority is BB next CC. If group does not have AA,BB,CC value then remains same (no need to update) . source Table. ID Name 11 AA 11 BB 11 CC 12 CC 12 02 12 BB 13 CC 13 03 13 45 13 65 14 02 14 05 15 12

Required result table: ID NAME 11 AA 11 AA 11 AA 12 BB 12 BB 12 BB 13 CC 13 CC 13 CC 13 CC 14 02 14 05 15 12

View Answers

December 10, 2012 at 4:06 PM

-- STEP 1: SELECT ID,Name, CASE WHEN Name LIKE 'AA' THEN 4 WHEN Name LIKE 'BB' THEN 3 WHEN Name LIKE 'CC' THEN 2 WHEN Name LIKE 'DD' THEN 1 ELSE 0 END AS HighRank INTO #Result1 FROM dbo.satti

-- STEP 2:

UPDATE Orginal SET Orginal.Name = Tmp1.Name FROM dbo.satti Orginal INNER JOIN( SELECT A.ID,A.Name,A.HighRank FROM #Result1 A INNER JOIN( SELECT ID,MAX(HighRank) AS High from #Result1 WHERE HighRank <> 0 GROUP BY ID) Temp ON A.ID = Temp.ID AND A.HighRank = Temp.High)Tmp1 ON Orginal.ID = Tmp1.ID

Ads









Related Tutorials/Questions & Answers:
Update a group of records with one value in the same group
Update a group of records with one value in the same group  I want to update my table group wise, i have three cases AA,BB,CC , if group of records.... If group does not have AA,BB,CC value then remains same (no need to update) . source
Mysql Group By
to group the result-set by specified one or more columns. Understand with Example... by clause: The Query group by is used to return the selected records from 'employee... Mysql Group By      
Advertisements
Mysql Group By
functions to group the result-set by specified one or more columns. Understand... group by clause: The Query group by is used to return the selected records from... Mysql Group By      
group by sorting
group by sorting  group by sorting of data in SQL
HQL group By.
HQL group By.  How to use group by in HQL?   In general group by clause is used with aggregate functions for grouping the result... order. It allows the Hibernate to fetch information from the database and group
GROUP BY IN NESTED QUERY
GROUP BY IN NESTED QUERY  Hello Every One, Query to use GROUP BY CLAUSE IN NESTED QUERY SELECT STATEMENT in mysql database.If u know please help me.thanks
multiple records on same panel
multiple records on same panel  i have multiple access of records and i want to display all of them at one panel.Each time a new panel opens for a keyrecord , i want just to show records on same panel or frame, whatever u can
SQL Avg Group By
SQL Avg Group By       SQL Avg Group By helps you to find out average value of numeric field in a table. The SQL GROUP BY clause is used with the SQL aggregate functions
SQL GROUP BY Example
. GROUP BY clause groups the same types of records of a table. This clause can... : select item, sum(quantity) from `order` group by item Now the records...SQL GROUP BY Example In this section we will discuss about the group
Update Records in Database
Update Records in Database       The Update Records in database is used to modify or change the value of records which match with a specified criteria. The update query
SQL Avg Group By
SQL Avg Group By       SQL Avg Group By helps you to find out average value of numeric field in a table. The SQL GROUP BY clause is used with the SQL aggregate functions
SQLl query count and group by
SQLl query count and group by  How to write a sql query to count and group by the data?   Sql query to count the data and group the data using group by function... Select Name, Count(Name) As Count From Table Group
xcode group folder
xcode group folder  I wanted to show all files in xcode in a group format.. left and right Group & Files. earlier it was showing in groups... the steps.. View -> Smart Groups -> All Files it'll group all the files
Hibernate Group by Clause
In this tutorial we will discuss about Hibernate group by with example
Artifacts of com.ineat-group
List of Artifacts of com.ineat-group maven depenency
Artifacts of com.rea-group
List of Artifacts of com.rea-group maven depenency
SQL Aggregate Functions Group By
SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate functions (like SUM) of the different numeric field for each individual group
Update value
Update value  How to update value of database using hibernate ?   Hi Samar, With the help of this code, you will see how can update database using hibernate. package net.roseindia.DAO; import
Group Discussion Dos and Don’ts
for a group discussion. There are two parts to it. One is that you need to be well... Group Discussion Dos and Don’ts       Introduction Group discussions are today an important
How to iterate over a checkbox group
group - it's id equals "MASTER" - contains 4 checkboxes. These checkboxes... group to appear below the MASTER group. If a user then checks "B" in MASTER, then the "B" group appears below the "A" group. If the user then unchecks
ModuleNotFoundError: No module named 'AuthZ-Group'
ModuleNotFoundError: No module named 'AuthZ-Group'  Hi, My Python... 'AuthZ-Group' How to remove the ModuleNotFoundError: No module named 'AuthZ-Group' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'AuthZ-Group'
ModuleNotFoundError: No module named 'AuthZ-Group'  Hi, My Python... 'AuthZ-Group' How to remove the ModuleNotFoundError: No module named 'AuthZ-Group' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'django-group-by'
ModuleNotFoundError: No module named 'django-group-by'  Hi, My... named 'django-group-by' How to remove the ModuleNotFoundError: No module named 'django-group-by' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-group-by'
ModuleNotFoundError: No module named 'django-group-by'  Hi, My... named 'django-group-by' How to remove the ModuleNotFoundError: No module named 'django-group-by' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'gf-group'
ModuleNotFoundError: No module named 'gf-group'  Hi, My Python...-group' How to remove the ModuleNotFoundError: No module named 'gf-group... to install padas library. You can install gf-group python with following
ModuleNotFoundError: No module named 'gf-group'
ModuleNotFoundError: No module named 'gf-group'  Hi, My Python...-group' How to remove the ModuleNotFoundError: No module named 'gf-group... to install padas library. You can install gf-group python with following
ModuleNotFoundError: No module named 'gf-group'
ModuleNotFoundError: No module named 'gf-group'  Hi, My Python...-group' How to remove the ModuleNotFoundError: No module named 'gf-group... to install padas library. You can install gf-group python with following
ModuleNotFoundError: No module named 'group-by-attr'
ModuleNotFoundError: No module named 'group-by-attr'  Hi, My... 'group-by-attr' How to remove the ModuleNotFoundError: No module named 'group-by-attr' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'group-lasso'
ModuleNotFoundError: No module named 'group-lasso'  Hi, My Python... 'group-lasso' How to remove the ModuleNotFoundError: No module named 'group-lasso' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'group-lasso'
ModuleNotFoundError: No module named 'group-lasso'  Hi, My Python... 'group-lasso' How to remove the ModuleNotFoundError: No module named 'group-lasso' error? Thanks   Hi, In your python environment
SQL Aggregate Functions Group By
)); Insert Value Into Stu_Table The insert into statement add the records... SQL Aggregate Functions Group By       SQL Aggregate Functions Group By return the aggregate

Ads