Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL update bit/flag based if field is blank/null

Author  Topic 

mruprai
Starting Member

12 Posts

Posted - 2012-04-03 : 04:19:48
Hi

i have a field, say 'Name' and another field which is a Bit - isNameMissing.

i want to update isNameMissing to 1 if 'Name' is blank

so something like

update table
set isNameMissing = isNullOrBlank(Name)

any advice on syntax? i am new to sql.

Kind regards

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-03 : 04:41:32
update table
set isNameMissing = 1
where isnull(Name,'') = ''


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mruprai
Starting Member

12 Posts

Posted - 2012-04-03 : 05:43:13
Hi

The trouble with that is it wouldnt set isNameMissing BACK to 0 if the data is changed, without another reset BIT to zero update
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-04-03 : 06:28:51
That wasn't a point in your first post

I would say you don't need that BIT.

Just ask the column if it is empty or not (see my where clause above for example).


No, you're never too old to Yak'n'Roll if you're too young to die.
edit: typo
Go to Top of Page
   

- Advertisement -