Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Scan tables and replace null values with a value
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
00573077
Message ID:
00573116
Vues:
25
>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--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform