Solved

update query Sql server 2005

Posted on 2011-09-06
3
232 Views
Last Modified: 2012-06-21
I have the following table named SalesData

Shop  CurrSales  PriorSales    Sales Diff   SalesMiss  SalesNeg
1201   0                20000          -20000                
1202   10000        0                  10000
1203    25000      24000           1000
1204    32000      32200            -200

I am trying to write an update query that for each shop will do the following

      update SalesMiss with a Y if either    CurrSales or PriorSales    = 0.  Otherwise, should be set to  N
     
      update SalesNeg with A Y if  salesdiff is < 0.  Otherwise should be set to N  



Here is the result I am looking for


Shop  CurrSales  PriorSales    Sales Diff   SalesMiss  SalesNeg
1201   0                20000          -20000           Y              Y
1202   10000        0                  10000            Y               N    
1203    25000      24000           1000              N               N
1204    32000      32200            -200              N               Y



0
Comment
Question by:johnnyg123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 500 total points
ID: 36490661
Update SalesData
SET SalesMiss = CASE WHEN CurrSales = 0 OR PriorSales = 0 THEN 'Y' ELSE 'N' END,
SalesNeg = CASE WHEN SalesDiff < 0 THEN 'Y' ELSE 'N' END
0
 
LVL 16

Expert Comment

by:brad2575
ID: 36490671
update sales data
set SalesMiss = CASE when currsales = 0 or priorsales = 0 then 'Y' ELSE 'N' END
SET SalesNeg = CASE WHEN salesdiff <0 THEN 'Y' ELSE 'N' END
0
 
LVL 16

Expert Comment

by:brad2575
ID: 36490677
lludden beat me by a little but same code :)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

690 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