• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 786
  • Last Modified:

SQL - set certain records to nothing - not null or zero - as if no data was in the columns for selected rows

HI ,

I am trying to update certain rows of a dbase and set certain columns in the rows to nothing. Someone has entered zeros in these columns and I need to update the table and set the rows back to empty (not null or zero)

have tried "  " and '  '  but getting  syntax errors. What can I use to set the rows back to empty as if there was no data there ?

1 Solution
UPDATE dbo.yourtable
SET yourfield=NULL
WHERE yourfield=0

>>>>>>I need to update the table and set the rows back to empty (not null

"nothing" IS null. So if you want to set tjose rows to nothing 0 can't be used as it is int, " " cannot be used as it is varchar... and it is not "nothing".  SO it shld be null

so the query shld be
update <tablename>
set <column>=null WHERE <column>=0
Anthony PerkinsCommented:
>>What can I use to set the rows back to empty as if there was no data there ?<<
If you do not want to use Null, than try this:

Update YourTableName
Set YourColumnName = ''
Where YourColumnName = '0'
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Anthony PerkinsCommented:
Also, the following question is considered abandoned, please attend to it:
pabby061203Author Commented:
Hi again and thanks.

I have found that it is slightly more complicated now. There are complete rows in this table that have been populated with a zero in each cell. I need to identify where the complete rows of zeros are - there may be other rows that have one or two zeros in them - I don't need to update those rows - it is only where a row is totally populated with zeros -not partially populated.

The column names are  Question1, question2, question3, question4 and question5. Tablename is tblanswers.
any ideas ?

thanks again.

pabby061203Author Commented:
Hi ,

I have solved this one myself ,  I used  

update tblanswers
set question1 = ' ' where question1 = 0 and question2 = 0 and question3 = 0 and question4 = 0 and question5 = 0

then I ran the same statement to set question2 = ' ' where question1 = 0 etc etc etc etc

Anthony PerkinsCommented:
>>I have solved this one myself <<
Great! Now please close the question.
pabby061203Author Commented:

I would like to close this question but am not seeing where to do this . Can you point me in the right direction,

Anthony PerkinsCommented:
>>Can you point me in the right direction<<
Sure.  It is all covered in the EE Help:

What are my choices?

Accept an Expert's Comment as the Answer http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi68
Accept Comments from more than one Expert (a Split) http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi69
Request a refund because you answered your own question (Refund/PAQ) http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi70 
Request a refund because no one answered your question (Delete) http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi71 
Abandon your question and leave the mess for someone else to clean up http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi78
Closed, 125 points refunded.
The Experts Exchange
Community Support Moderator of all Ages

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now