Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

update query Sql server 2005

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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