SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Replace the Null values


Replace the Null values

Author
Message
HBK_4700
HBK_4700
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2099 Visits: 1839
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.
bitbucket-25253
bitbucket-25253
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16017 Visits: 25280
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
HBK_4700
HBK_4700
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2099 Visits: 1839
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.
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)SSC Guru (218K reputation)

Group: General Forum Members
Points: 218560 Visits: 41997
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.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
HBK_4700
HBK_4700
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2099 Visits: 1839
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.

Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13538 Visits: 4077
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;-)
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13538 Visits: 4077
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;-)
HBK_4700
HBK_4700
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2099 Visits: 1839
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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (228K reputation)SSC Guru (228K reputation)SSC Guru (228K reputation)SSC Guru (228K reputation)SSC Guru (228K reputation)SSC Guru (228K reputation)SSC Guru (228K reputation)SSC Guru (228K reputation)

Group: General Forum Members
Points: 228667 Visits: 46343
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, MVP, M.Sc (Comp Sci)
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


janki
janki
SSC-Enthusiastic
SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)

Group: General Forum Members
Points: 145 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))
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search