Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql select to remove blank fields
Message
From
16/07/2019 07:55:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
15/07/2019 14:35:09
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01669607
Message ID:
01669624
Views:
93
Likes (1)
>>
>>Select t1.field1, t2.field2, t3.field3, nvl(t1.group, Nvl(t2.group, t3.group)) as group, sys(2015) as newId ;
>>from (Select field1, group ;
>>from Table1 ;
>>where !Empty(field1)) t1 ;  
>>full join (Select field2, group ;
>>from Table1 ;
>>where !Empty(field2)) t2 on t1.group = t2.group ;
>>full join (Select field3, group ;
>>from Table1 ;
>>where !Empty(field3)) t3 on Nvl(t1.group, t2.group) = t3.group
>>
>
>An slightly edited version if you only want spaces and not .NULL. fields in the output cursor:
>
SELECT  NVL(t1.field1, SPACE(LEN(table1.field1))) AS field1, ;
>        NVL(t2.field2, SPACE(LEN(table1.field2))) AS field2, ;
>        NVL(t3.field3, SPACE(LEN(table1.field3))) AS field3, ;
>        NVL(t1.group, NVL(t2.group, t3.group)) AS group, ;
>        SYS(2015) AS newId ;
>    ;
>    FROM          (SELECT field1, group FROM table1 WHERE !Empty(field1)) t1 ;
>        FULL JOIN (SELECT field2, group FROM table1 WHERE !Empty(field2)) t2 ON t1.group                = t2.group ;
>        FULL JOIN (SELECT field3, group FROM table1 WHERE !Empty(field3)) t3 ON NVL(t1.group, t2.group) = t3.group ;
>    ;
>    INTO CURSOR c_scrunched
>
In that case I would prefer using Cast(), instead of space. ie:
SELECT  NVL(t1.field1, CAST('' as c(10)) AS field1, ...
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform