?
Solved

update query Sql server 2005

Posted on 2011-09-06
3
Medium Priority
?
233 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

770 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