spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

SQL split duplicates and rename


Test Data

DECLARE @TABLE TABLE (EMPID INT,
UserName VARCHAR(10))
INSERT INTO @TABLE VALUES
(1 ,'Josh') ,(2 ,'John')  ,(2 ,'Kate'),
(2 ,'Jorge'),(3 ,'Taylor'),(3 ,'Morgan'),4
,'Nathan')

UPDATE Query

;WITH CTE AS 
(
 SELECT * , ROW_NUMBER() OVER (ORDER BY
EMPID,UserName) + (SELECT MAX(EMPID) FROM @TABLE)
New_ID
 FROM @TABLE t
 WHERE NOT EXISTS (SELECT EMPID , MAX(UserName) AS
UserName1
                  FROM @TABLE
                  WHERE  EMPID = t.EMPID
                  GROUP BY EMPID
                  HAVING   MAX(UserName) =
t.UserName)
)
UPDATE CTE 
 SET EMPID = New_ID

RESULT

SELECT * FROM @Table

╔═══════╦══════════╗
║ EMPID ║ UserName ║
╠═══════╬══════════╣
║     1 ║ Josh     ║
║     2 ║ Kate     ║
║     3 ║ Taylor   ║
║     4 ║ Nathan   ║
║     5 ║ John     ║
║     6 ║ Jorge    ║
║     7 ║ Morgan   ║
╚═══════╩══════════╝

Categories : SQL

Related to : SQL split duplicates and rename
Perl - split command with regex - split numeric and strings
(-?d+(.d+)?)|([a-zA-Z ]+) Try this.See demo.Grab the captures.Remove the empty ones. http://regex101.com/r/lZ5mN8/35

Categories : Regex
Regex Split: Split column into Name, percentage andsolvent
Don't overcomplicate this by using one unreadable regex. Based on what you've said, your separators are well defined (the last space and the last %). In JavaScript, for example, you could use: var str = "A-6-b 10/%XYZ"; var firstSeparator = str.lastIndexOf(' '); var secondSeparator = str.lastIndexOf('%'); var name = str.substring(0, firstSeparator); var percentage = str.substring(firstSeparato

Categories : Regex
Rename csrfmiddlewaretoken
This is string is hardcoded in django/middleware/csrf.py: # Check non-cookie token for match. request_csrf_token = "" if request.method == "POST": request_csrf_token = request.POST.get('csrfmiddlewaretoken', '') if request_csrf_token == "": # Fall back to X-CSRFToken, to make things easier for AJAX, # and possible for PUT/DELETE

Categories : Python
How to rename a printer in C++ on Windows?
You can use the SetPrinter function to rename a printer. You would set the Level parameter to 2 and the pPrinter parameter would point to a PRINTER_INFO_2 structure. The PRINTER_INFO_2::pPrinterName field lets you change the printer name. Note that the docs for SetPrinter say: To modify the current printer settings, call the GetPrinter function to retrieve the current settings into a PRINT

Categories : C++
MySQL rename column
No, you've got it right. ALTERis used to change existing database objects (for example the name of a table - it's a data definition statement (DDL)). Using ASgives your result an alias, so this statement: SELECT COUNT(*) AS num FROM TABLE_A would count the number of rows in the table and output the result in a column named num. Note that the count is not for distinct rows unless you specify it,

Categories : Mysql
Recently Add
SQL command to insert two primary keys into third table
How to do a registerform by ASP.NET VB SQL
Shortest time and trip between two stops across many trip options (GTFS)
Using IN and EXISTS subquery with AND operation instead of OR?
How to select multiple alias columns from the same table
Delete records from a given table
date manipulation in postgresql
PSQL query with join query from a db newbie
Protect LocalDB from user access
Update field with combined contents from other fields
SQL select unique records under certain priority and conditions from multiple columns
Multiply quantities for all parent child relationships
I'm having an issue running a query from a batch file
Concatenate strings while filtering by another column in SQL Server view
Parsing Dynamic XML to SQL Server tables with Parent and child relation
Using MERGE for delete and insert in oracle
how to display the pre value and post value of a column after updating it?
sql loop to fill up date between two time stamps
With SQL/TSQL, how can I use STUFF within this WHILE clause?
Challenging db table and query
Query to fetch row corresponding to Max value in SQL
Oracle SQL - ORA-00936 on DATE()
how to split single row into multiple row in db2?
Combine fields into one column
How can I perform an SQl where query then list properly?
SQL - Selection of the oldest order for every customer (join two tables)
Sum two counts in a new column without repeating the code
Creating multiple sum fields based upon criteria in another field in MS access 2007
Grouping by two values in same table
MS SQL last record
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.