Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sql select to remove blank fields
Message
From
15/07/2019 17:11:40
 
 
To
15/07/2019 14:35:09
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01669607
Message ID:
01669616
Views:
77
>>
>>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
>
Cetin,

I am trying to put your code into my project. In my project the table consists of 7 memo fields so when I write:
	Select T1.mdag1, T2.mdag2, T3.mdag3, T4.mdag4, T5.mdag5, T6.mdag6, T7.mdag7 ,;
		Nvl(T1.dagdeel, nvl(T2.dagdeel, nvl(T3.dagdeel, nvl(T4.dagdeel, nvl(T5.dagdeel, nvl(T6.dagdeel, T7.dagdeel)))))) As dagdeel, ;
     Sys(2015) As newId ;
		from (Select mdag1, dagdeel ;
		from crsReport0 ;
		where !Empty(mdag1)) T1 ;
		full Join;
			(Select mdag2, dagdeel ;
			from crsReport0 ;
			where !Empty(mdag2)) T2 On ;
			Nvl(T1.dagdeel, nvl(T1.dagdeel, nvl(T3.dagdeel, nvl(T4.dagdeel, nvl(T5.dagdeel, nvl(T6.dagdeel, T7.dagdeel)))))) = T2.dagdeel ;
		full Join ;
			(Select mdag3, dagdeel ;
			from crsReport0 ;
			where !Empty(mdag3)) T3 On ;
			Nvl(T1.dagdeel, nvl(T1.dagdeel, nvl(T2.dagdeel, nvl(T4.dagdeel, nvl(T5.dagdeel, nvl(T6.dagdeel, T7.dagdeel)))))) = T3.dagdeel ;
		full Join ;
			(Select mdag4, dagdeel ;
			from crsReport0 ;
			where !Empty(mdag4)) T4 On ;
			Nvl(T1.dagdeel, nvl(T1.dagdeel, nvl(T2.dagdeel, nvl(T3.dagdeel, nvl(T5.dagdeel, nvl(T6.dagdeel, T7.dagdeel)))))) = T4.dagdeel ;
		full Join ;
			(Select mdag5, dagdeel ;
			from crsReport0 ;
			where !Empty(mdag5)) T5 On ;
			Nvl(T1.dagdeel, nvl(T1.dagdeel, nvl(T2.dagdeel, nvl(T3.dagdeel, nvl(T4.dagdeel, nvl(T6.dagdeel, T7.dagdeel)))))) = T5.dagdeel ;
		full Join ;
			(Select mdag6, dagdeel ;
			from crsReport0 ;
			where !Empty(mdag6)) T6 On ;
			Nvl(T1.dagdeel, nvl(T1.dagdeel, nvl(T2.dagdeel, nvl(T3.dagdeel, nvl(T4.dagdeel, nvl(T5.dagdeel, T7.dagdeel)))))) = T6.dagdeel ;
		full Join ;
			(Select mdag7, dagdeel ;
			from crsReport0 ;
			where !Empty(mdag3)) T7 On ;
			Nvl(T1.dagdeel, nvl(T1.dagdeel, nvl(T2.dagdeel, nvl(T3.dagdeel, nvl(T4.dagdeel, nvl(T5.dagdeel, T6.dagdeel)))))) = T7.dagdeel ;
		Into Cursor crsReport
SQL does not like this, 'T3 is not found'
for your info:
dagdeel = group as in table1
mdag1 to mdag7 are field1 to field7 as in table1
crsReport0 = table1 from my testing you used to make a fine working code for 3 fields, which was the option.
Now the serious work comes for 7 fields and I am stuck.
I am sure I do make some basic mistake in this coding, however I can't find it. Would you be able to pinpoint?

Regards,
Koen

@Rick,
Rick I am afraid your solution, for only spaces and no .NULL. does not work as such since I am not working with text but memo fields.
Regards,
Koen
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform