Solved

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

Posted on 2006-03-21
11
763 Views
Last Modified: 2010-07-27
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 ?

thanks.
0
Comment
Question by:pabby061203
11 Comments
 
LVL 9

Expert Comment

by:paelo
Comment Utility
UPDATE dbo.yourtable
SET yourfield=NULL
WHERE yourfield=0



-Paul.
0
 
LVL 11

Expert Comment

by:star_trek
Comment Utility
>>>>>>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
                         
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
>>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'
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Also, the following question is considered abandoned, please attend to it:
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21709703.html
0
 

Author Comment

by:pabby061203
Comment Utility
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.




0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:pabby061203
Comment Utility
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

thanks
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
>>I have solved this one myself <<
Great! Now please close the question.
0
 

Author Comment

by:pabby061203
Comment Utility
HI.

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

thanks
0
 
LVL 75

Expert Comment

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

What are my choices?
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/help.jsp#hi67

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
0
 

Accepted Solution

by:
GranMod earned 0 total points
Comment Utility
Closed, 125 points refunded.
GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now