sql server - T-SQL Grouping rows from the MAX length columns in different rows (?) -


I make a way to combine rows in a row based on the longest string in any line Trying on a line key

Example

  Create a table test1 (akey integer not tap, text 1 varchar (50) zero, text 2 varchar (50 ) Enter zero, text 3 varchar (50) zero in test1 value (1, 'winchester road', 'crawl', zero) in test1 value (1, 'winches Enter the test1 value (1, 'Winchester Road', 'Crowley Asset', 'P21869') in test1 value (1, 'Winchester Road', 'Crowley', '' Road '', 'Crowley', 'P21869' (2, 'Smith Closed', 'Birmingham North East', 'P53342') into test1 value (2, '', 'Birmingham', 'P53342B') in test1 value (2, Enter 'Smith Chlorine.', Zero, 'P53342B') in the test1 value (2, 'Smith with these lines, I will look for the following:  
  1 Winchester Road, Crawly, Closed Do, 'B Property, p 2186 9a2, close closure, birmingham northeast, p 53342b,  

Edit : The above results should be in the table instead of just a comma separated string

As you can see in the results, the output is the longest text in the range of area 'akey' Should be a column.

I'm trying to come up with a solution, not many subcategories are included in each column, the actual table has 32 columns and 13 million rows.

The reason for this is that I am preparing a clean-up table with the best results in each column for one ID per line

This is my first post , So tell me that you need more information, and I am happy to hear about any best practice about the posting that I have broken!

thanks

  K.E., (Top1T1Text1 to Test1T1 where T1AE = AKEEEE and LAN (T1.TEXT1) = MAX (LAN (Atext1 ))) As TXT1, (Selection Top1 T2.text2 from test1 T2 to T2.akey = A.akey and Lane (T2.TEXT2) = Max (LEN (A.text2)) as text 2 (Test1 T3 from where selection top 1 T3.text3 T3.akey = A.akey and lane (T3.TEXT3) = Max (LEN (A.text3)) as text 3 as a group from test1 By A.akey  

I just feel Or you said that you have 32 columns is not a good way for me to do so, unless UNPIVOT not allow you to create separate lines (one key, text) for each text column.

Edit: Today it is not a chance to end, but UNPIVOT looks useful:

 ; P Unprivate as column (selection one, [column], from column value (SELECT X.Akey, X.Text1, X.Text2, X.Text3 to test1x) [column column [IN] for column (Text1, Text2, Text3)) * Order from column, [column], LAN (column value)  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -