Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Replace the Null values Expand / Collapse
Author
Message
Posted Thursday, September 16, 2010 7:04 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:41 AM
Points: 361, Visits: 1,781
I need to replace the NULL values with empty space in a sql server 2005 table column data. Is there any way to replace data in table itself.

Post #987839
Posted Thursday, September 16, 2010 7:30 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 10:58 AM
Points: 5,333, Visits: 25,272
I do not understand why you wish to do this to values in a table and not in the T-SQL statement which selects the data from the table, but you could look at this to understand the ISNULL function, which you could then use in a update statement.

[url][http://technet.microsoft.com/en-us/library/ms184325(SQL.90).aspx/url]


If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #987847
Posted Thursday, September 16, 2010 7:58 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:41 AM
Points: 361, Visits: 1,781
Actually I need to export the data to excel file. Some the coulumns data have NULL values.

I have used ISNULL function and wrote a below T-SQL statement, but getting 0 in place of NULL where as I am looking for a empty space

Just wondering whether SQL does't support empty space
or
is there any other ways to get it done.

Thank you.
Post #987853
Posted Thursday, September 16, 2010 9:46 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:47 AM
Points: 35,347, Visits: 31,882
laddu4700 (9/16/2010)
Actually I need to export the data to excel file. Some the coulumns data have NULL values.

I have used ISNULL function and wrote a below T-SQL statement, but not getting 0 in place of NULL where as I am looking for a empty space

Just wondering whether SQL does't support empty space
or
is there any other ways to get it done.

Thank you.


SQL does support empty space... just not for numerics. You'll need to convert your numerics to something character based so you can replace nulls with an empty string. Excel will take it all in stride during the import.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #987867
Posted Thursday, September 16, 2010 10:17 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:41 AM
Points: 361, Visits: 1,781
Hi Jeff, Thanks for your reply.

I am getting empty space by using below query. Please correct me if I am wrong.

USE MYDB;
GO
select UserName, ISNULL(NULL, '') AS 'UserID'
FROM Tablename;
GO



Jeff Moden (9/16/2010)
laddu4700 (9/16/2010)
Actually I need to export the data to excel file. Some the coulumns data have NULL values.

I have used ISNULL function and wrote a below T-SQL statement, but not getting 0 in place of NULL where as I am looking for a empty space

Just wondering whether SQL does't support empty space
or
is there any other ways to get it done.

Thank you.


SQL does support empty space... just not for numerics. You'll need to convert your numerics to something character based so you can replace nulls with an empty string. Excel will take it all in stride during the import.
Post #987878
Posted Friday, September 17, 2010 1:35 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 6, 2014 5:46 AM
Points: 2,840, Visits: 3,969
laddu4700 (9/16/2010)
Hi Jeff, Thanks for your reply.

I am getting empty space by using below query. Please correct me if I am wrong.

USE MYDB;
GO
select UserName, ISNULL(NULL, '') AS 'UserID'
FROM Tablename;
GO



Jeff Moden (9/16/2010)
laddu4700 (9/16/2010)
Actually I need to export the data to excel file. Some the coulumns data have NULL values.

I have used ISNULL function and wrote a below T-SQL statement, but not getting 0 in place of NULL where as I am looking for a empty space

Just wondering whether SQL does't support empty space
or
is there any other ways to get it done.

Thank you.


SQL does support empty space... just not for numerics. You'll need to convert your numerics to something character based so you can replace nulls with an empty string. Excel will take it all in stride during the import.

Use this
USE MYDB;
GO
select UserName, ISNULL(Userid, '') AS 'UserID'
FROM Tablename;
GO







-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #987938
Posted Friday, September 17, 2010 1:37 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, October 6, 2014 5:46 AM
Points: 2,840, Visits: 3,969
See
declare @t table ( id int )

insert into @t
select 1
union
select 2
union
select null

select *, isnull(id, '') as new from @t



-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #987939
Posted Friday, September 17, 2010 11:52 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, February 27, 2014 10:41 AM
Points: 361, Visits: 1,781
I am getting empty space if I use below query

USE MYDB;
GO
select UserName, ISNULL(NULL, '') AS 'UserID'
FROM Tablename;
GO

I am getting 0 if I use below query
USE MYDB;
GO
select UserName, ISNULL(Userid, '') AS 'UserID'
FROM Tablename;
GO
--
But I need to replace NULL with empty space on where I have the NULL values.
In UserID column data all the rows are not NULL, only some of the rows. I need to replace them only with empty space.
Post #988465
Posted Friday, September 17, 2010 11:55 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:09 PM
Points: 40,172, Visits: 36,560
USE MYDB;
GO
select UserName, ISNULL(Cast(Userid AS VARCHAR(10)), '') AS 'UserID'
FROM Tablename;
GO

You can't set an int column to '', it'lll be implicitly converted to 0. Hence the int column needs to become character data first.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #988473
Posted Wednesday, October 20, 2010 11:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, May 8, 2012 7:53 AM
Points: 101, Visits: 349
If You have say table "Employee" and column Emp_Name(that contains , NULL values)
Then.

Example:
Update Employee
SET Emp_Name = ISNULL(Emp_Name , ' ')
where <condition>.....................(If required, or all wherever there are NULL value in Emp_Name column,
those records will get replaced by blank value(Means nothing))
Post #1007918
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse