none
SQL - Group By with text?

    Question

  • Hello, 

    I have a dataset that needs to be grouped by/ washed?
    There is 300 000 rows that i want to group by /  Erase all NULL values and minimize the amount of rows. 

    The problem seems to be my Textcolumns. 

    Problem

    Key          Field          TextGER            TextDen           TextSPA

    33220 Field1 SPACECARROT  NULL                 NULL

    33220 Field1 NULL           NULL                 SPACECARROT  

    33220 Field1 NULL                 SPACECARROT  NULL

     

    Solution

    33220 Field1 SPACE carrot    SPACE carrot      SPACE carrot

     

    Happy for good answers and solutions!

     

    B3rra

    Wednesday, April 07, 2010 3:20 PM

Answers

  • select Key, Field, Max(TextGer) as TextGer, Max(TextDen) as TextDen, max(TextSpa) as TextSpa from myTable

    group by Key, Field

    If the text fields are test, first cast them to varchar(max).


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Proposed as answer by Kalman TothModerator Friday, April 09, 2010 5:35 AM
    • Marked as answer by KJian_ Tuesday, April 13, 2010 6:27 AM
    Wednesday, April 07, 2010 3:23 PM