sql - Stored Procedure algorithm taking 9 hours- better way of doing this? -


I need to create a SQL stored procedure that is basically an existing table (approximately 150,000 lines) Updates with

The table which will end this stored procedure is basically a list of people, their names, addresses, etc.

Now the algorithm for the person's ID is as follows: - First take the first 4 letters of the first person - take the first 2 characters of the persons with the last name - at the end with a count number 0 Do the rest pad with, unless the area is 8 characters.

For example, John Smith's name would be 'JOHNSM00' if 2 were John Smith, the next person will be identified as JOHNSM01 For example, if the person's name was FI LYNN, then the ID will be FILY0000.

I've got the following stored procedure written by me, but it takes about 9 hours to run! Is there a better way of doing what I am missing?

  Optional process [dbo]. [LM_SP_UPDATE_PERSON_CODES] DECLARE @NAMEKEY NVARCHAR (10) DECLARE @NEWNAMEKEY NVARCHAR (10) DECLARE @LENGTH INT DECLARE @KEYCOUNT INT DECLARE @ INT DECLARE @ PADDING NVARCHAR (8) DECLARE @ Cursor Decision for Individuals @FIRSTNAME NVARCHAR (30) DECLARE @LASTNAME NVARCHAR (30) from SEP @PADDING = '00000000' --FIRST if called old new none EXIST updated LM_T_PERSONS SET NEW_NAMEKEY = NULL SET @ PERSONS = Select NAMEKEY, cursor NAME_2, LM_T_PERSONS NAME_1 the OPEN @PERSONS FETCH NEXT @NAMEKEY, @FIRSTNAME, @LASTNAME WHELE @@ FETCH_STATUS = 0 BEGIN - check lens make sure to make the first name that nothing 4 SET @LENGTH = LEN (@FIRSTNAME) if @LENGTH & gt; 4 SET @LENGTH = 4 SET @NEWNAMEKEY = SUBSTRING (@ FIRSTNAME, 1, @ LENGTH) - More than 2 sets to clear the last name length @LENGTH = LEN (@LASTNAME) if @LENGTH & gt; 2 SET @lenth = 2 SET @nunmeke = @nunmeke + Substring (@ LastName, 1, @ length) sets @lenth = Experience (@nunmeke) set @i = 0 SET @pading = Substring ( "00000000", 1,8 - LAN (@NEWNAMEKEY) - LAN (converter (Anviacaaraar (8) @ I))) - If the key went first set, @KEYCOUNT = (SELECT COUNT (1) of LM_T_PERSONS where NEW_NAMEKEY = @NEWNAMEKEY + @PADDING + Convert (NVARAR (8), @ I) WHILE @KEYCOUNT & gt; 0 BEGIN SET @I = @ I + 1 SET @PADDING = SUBSTRING ( '00000000', 1,8 - LAN (@ Nunike) - ln (convert (Anviaraaraar (8), @ i))) SET @KEYCOUNT = (SELECT (1) Elm_ T_PERSONS where where NEW_NAMEKEY = @NEWNAMEKEY + @PADDING + CONVERT (NVARCHAR (8), @ I)) update LM_T_PERSONS SET NEW_NAMEKEY = @NEWNAMEKEY + @PADDING + CONVERT (NVARCHAR (8), @ I) name = Please contact @NAMEKEY FETCH @NAMEKEY, @FIRSTNAME, @LASTNAME and the person who has been discontinued with the next person    

This can do without some cursor:

  update SE SET NAMEKEY = FIRSTNAME + LASTNAME + REPLIC ATE ( '0', 8 - LEN (first) - LEN (LASTNAME) - LAN (I)) + I (selected Elm_ T_PERSONS as PM name, left (called 2, 4) first name, left ( name, 2) as the final, convert (Anviaraaaraar, Arou_67 () left (NAME_2, 4), lEFT (NAME_l, 2) NAMEKEY by order)) Pi.a.an.ankkeki .e. = Data. As data on NAMEKEY)   

You can confirm q Yuri here:

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -