Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Scan tables and replace null values with a value
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
00573077
Message ID:
00573116
Views:
24
>How do I scan all tables in my database for null values and replace them with 0 for a numeric field and an empty string for character fields ??

The following select will return a list of the fields that allow nulls
SELECT Table_name, Column_name, Data_type FROM INFORMATION_SCHEMA.Columns
	WHERE Is_Nullable = 'YES' And table_name In (
		SELECT table_name FROM INFORMATION_SCHEMA.TABLES
			WHERE table_type = 'BASE TABLE' )
You can create cursor based on that, loop trhu it and build dynamic UPDATE statement for each column. It can be executed using EXECUTE command or sp_executesql SP.
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform