Question

thanks for review this

i have easily problem , i know it will solve by you frinds

i have a table with 14 columns , 8 of cols are numeric (int , biging , numeric(18,0)) and other cols data type are in text value such as char(10), varchar(255),Nvarchar(4000) this table filled by same random value and in all cols (except ID) have lot of null value .

i want make one or more Stored Procedure that Fill all null cell in numeric columns to 0 and all nulls in string columns to 'no value'.

if this SP will return count of all null values in all columns , its amazing

thanks so much

Was it helpful?

Solution

You can use a loop in store procedure but best way is you check all column for null value because may be any column have various data type.

i hope this be helpful .

OTHER TIPS

Update Table1
set col1='0'
where co1 is null

And so on...

You can update as stated above but if you need to have a default field as 0 then you should have used default on table creation

CREATE TABLE dbo.Something
(
    id               INT IDENTITY(1, 1),
    col1        INT DEFAULT 0
)

but if its legacy code than on insert proc you could have used like

CREATE PROCEDURE [dbo].[spa_CRUDSomething]
    @flag CHAR(1)
   ,  @col1 INT = 0
AS 

Usually the problem isn't in doing fixes rather on way of fixing the fixes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top