Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Removing NULL values and NULL indicator from a table
Message
From
18/05/2006 15:16:17
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01123353
Message ID:
01123369
Views:
22
This creates a table of all numeric fields in the DB that are nullable or defaulted to NULL. To get all data types just add the datatypes to lcNumericType.

This grabs a few other attributes but should work.
*!* utility to retreive all nullable fields
*!* 02.27.06 bxk
LOCAL lcTable, lnRow, lnElem, laFields[1], lnFields, lcNumericType

lcNumericType = 'NIYR'

CLOS DATA ALL

USE YourDatabase.DBC NOUPDATE
USE YourDatabase.DBC IN 0 AGAIN ALIAS child NOUPDATE

SET DELETED ON
SELECT ;
		.F. AS lUpDatable, ;
		.F. AS lAllowNull, ;
		SPACE(32) AS cDefault, ;
		YourDatabase.objecttype, ;
		PADR(TRIM(YourDatabase.objectname) + "." + child.objectname, 64) AS cField, ;
		YourDatabase.objectname AS ctable, ;
		child.objectname ;
	FROM child ;
	INNER JOIN YourDatabase ;
		ON child.parentid = YourDatabase.objectid ;
	WHERE child.objecttype = 'Field' ;
	ORDER BY 4, 5 ;
	INTO TABLE AllFields

CLOS DATA ALL

OPEN DATABASE YourDatabase

SET DELETED OFF
USE AllFields IN 0
SELECT AllFields
SCAN
	IF objecttype = 'View'
		lcTable = TRIM(ctable)
		IF 'NULL' $ DBGETPROP(lcTable + '.' + TRIM(objectname), 'FIELD', 'DefaultValue')
			REPLACE lUpDatable WITH DBGETPROP(lcTable, 'VIEW', 'SendUpdates')
			REPLACE lAllowNull WITH DBGETPROP(lcTable, 'VIEW', '')
			REPLACE cDefault WITH '.NULL.'
			
		ELSE
			DELETE NEXT 1
		
		ENDIF
		
	ENDIF
	
	IF objecttype = 'Table'
		USE(TRIM(cTable)) IN 0 ALIAS Current
		lnFields = AFIELDS(laFields, 'Current')
		IF lnFields > 0 
			lnElem = ASCAN(laFields, TRIM(UPPER(objectname)))
			IF lnElem > 0
				lnRow = ASUBSCRIPT(laFields, lnElem, 1)		&& get the row
				
				IF laFields[lnRow, 2] $ lcNumericType
					REPLACE lAllowNull WITH laFields[lnRow, 5] IN AllFields
					
				ELSE
					DELETE NEXT 1
					
				ENDIF
				
			ENDIF
			
		ENDIF
		
		USE IN SELECT('Current')
		
	ENDIF
	
ENDSCAN


SELECT AllFields
BLANK FIELD lupdatable FOR ! lUpdatable
BLANK FIELD lallownull FOR ! lAllowNull

SELECT * ;
	FROM AllFields ;
	WHERE lAllowNull ;
	OR cDefault = '.NULL.' ;
	INTO TABLE NullFields

CLOS DATA ALL
HTH

Bruce

>Kind of a long story - but - I was having trouble getting a .dbf to be the data source of a mail merge. Word came back with "Word was unable to open the data source". When I looked closer at the table in the data session, I noticed that the date fields were marked as nullable. When I removed that check, then Word Mail Merged my table. None of the fields values were actually NULL, just the indicator that they could be NULL stopped the merge.
>
>So ... I want to put some generic code together that will read any .dbf, field by field, and determine if the value is null to set to EMPTY, and to set to NOT NULL. Can someone get me started?
>
>Thanks
>
>Brenda
Previous
Reply
Map
View

Click here to load this message in the networking platform