SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating Nulls to No Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 09/13/2013 :  05:55:45  Show Profile  Reply with Quote
Hey guys

Quick question
Aim- update Nulls to ‘no’

This is my query but i am keep returning (0 row(s) affected) when i know there is around 100,000 rows which needs to be changed


Update #Mason
set Clientline = 'No'
where Clientline = 'Null'

Would appreciate any help available

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/13/2013 :  05:57:35  Show Profile  Visit webfred's Homepage  Reply with Quote
quote:
Originally posted by masond

Hey guys

Quick question
Aim- update Nulls to ‘no’

This is my query but i am keep returning (0 row(s) affected) when i know there is around 100,000 rows which needs to be changed


Update #Mason
set Clientline = 'No'
where Clientline = 'Null'

Would appreciate any help available



where Clientline is null


Too old to Rock'n'Roll too young to die.

Edited by - webfred on 09/13/2013 05:57:56
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 09/13/2013 :  05:58:41  Show Profile  Reply with Quote
HA webfred

i just worked it out

the code is
update #Mason
set Clientline = 'No'
where Clientline is null
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 09/13/2013 :  06:01:44  Show Profile  Reply with Quote
HOw do you default Nulls to blank
Go to Top of Page

divya.ce
Starting Member

India
16 Posts

Posted - 09/13/2013 :  06:21:27  Show Profile  Reply with Quote
When you create columns in your table, add a default constraint as '' to that column, or always check for null entries in your where clause as "WHERE ISNULL(ClientName ,'') ='' "
ISNULL will check the column's value, if NULL then change it to blank or whatever you give as the second parameter.
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2210 Posts

Posted - 09/13/2013 :  06:27:43  Show Profile  Reply with Quote
update #Mason
set Clientline = 'No'
where NULLIF(Clientline, '') is null --- If you have blank for NULL column

--
Chandu
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 09/13/2013 :  07:57:27  Show Profile  Visit webfred's Homepage  Reply with Quote
see this to understand:

create table #Mason (Id int identity(1,1),  Clientline varchar(255), test varchar(255))
go

insert #Mason(test)
select 'first test without default'

select * from #Mason

go


alter table #Mason add constraint Clientline_value default 'No' for Clientline
go

insert #Mason(test)
select 'second test with default'

select * from #Mason

go

drop table #Mason




Too old to Rock'n'Roll too young to die.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000