?
Solved

Compare Expiration dates

Posted on 2014-02-05
6
Medium Priority
?
183 Views
Last Modified: 2014-02-25
I have a stored  procedure that assign a dollar amount based on an expiration date.  Initially a user would pay a $1000 for each brand family.  But if the user would like to add styles they can do so without being charged.  Therefore  I have the case statement below.

 SELECT l.vchTransNum, l.vchManufacturer, b.vchBrand AS 'Brand Family', 
      CASE
       
      --check online tables to see if brands have been submitted for this particular manu
      WHEN EXISTS (SELECT vchBrand, vchManufacturer 
      FROM tblOnlineCLBrands o  WHERE o.vchBrand = b.vchBrand and o.vchManufacturer =l.vchManufacturer) 
      THEN 0.00
      
      
       --checks in-house table to see if brands have been submitted for this manu and if this is renewal year
      WHEN EXISTS (SELECT vchBrand, vchManufacturer   
      FROM tblCLBrands bf
      INNER JOIN tblCLPermit p on bf.vchRecordID = p.vchRecordID 
      --WHERE bf.vchBrand = b.vchBrand and bf.vchManufacturer =l.vchManufacturer and Year(DATEADD (Year , 3, dtpermitDate))<= YEAR(GetDate()) )
      WHERE bf.vchBrand = b.vchBrand and bf.vchManufacturer =l.vchManufacturer and dtExpirationDate > GETDATE())
      THEN 0.00
     
      
      ELSE 1000
      END AS 'Cost of Brand'
            
      FROM tblOnlineCLTempLab l
      
      INNER JOIN (Select distinct vchBrand, vchTransNum  from tblOnlineCLTempBrands) b on l.vchTransNum  = b.vchTransNum 
      
      WHERE  l.vchTransNum = @TransNum
      GROUP BY l.vchTransNum , l.vchManufacturer, b.vchbrand

Open in new window


The second case line is giving me a hard time.  If users want to renew before the expiration date, it still assigns it zero dollars instead of $1000. How can I program it to allow the user to pay before their date expires?
0
Comment
Question by:dlavar
[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
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:Koen Van Wielink
ID: 39837818
There's nothing obviously wrong with the query as far as I can tell, so is it possible that the first case statement always evaluates to True?
0
 
LVL 25

Expert Comment

by:chaau
ID: 39837826
Could it be that dtExpirationDate  exists in both tblCLBrands and tblCLPermit tables, or in tblOnlineCLTempLab table itself?
0
 

Author Comment

by:dlavar
ID: 39838858
When I commented out the first case statement, it resulted in a $1000. The Expiration date is only in the Permit table.  I'm thinking that I may have to set a grace period of when the can renew their permit.
0
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

 
LVL 13

Expert Comment

by:Koen Van Wielink
ID: 39838916
In that case you'll have to check why the first case statement evaluates to True when you don't want it to. The problem is most likely not with the expiration date.
0
 

Accepted Solution

by:
dlavar earned 0 total points
ID: 39874646
I had to set a grace period of 60 days in the stored procedure

 SELECT l.vchTransNum, l.vchManufacturer, b.vchBrand AS 'Brand Family', 
      
      CASE
      -- check online tables to see if brands have been submitted for this particular manu
	  WHEN EXISTS (SELECT vchBrand, vchManufacturer 
	  FROM tblOnlineCLBrands o  WHERE o.vchBrand = b.vchBrand and o.vchManufacturer =l.vchManufacturer) 
	  THEN 0.00
      
      --checks in-house table to see if brands have been submitted for this manu and if this is renewal year
      --If today is 60 days before the expiration (before renewal time), charge 0. 
      WHEN EXISTS (SELECT vchBrand, vchManufacturer 
      FROM tblCLBrands bf
      INNER JOIN tblCLPermit p on bf.vchRecordID = p.vchRecordID 
      WHERE bf.vchBrand = b.vchBrand and bf.vchManufacturer =l.vchManufacturer and  GETDATE() < DATEADD(Day , -60, dtExpirationDate) )
      THEN 0.00
               
      
      ELSE 1000
      END AS 'Cost of Brand'
            
      FROM tblOnlineCLTempLab l
      INNER JOIN (Select distinct vchBrand, vchTransNum  from tblOnlineCLTempBrands) b on l.vchTransNum  = b.vchTransNum 
      WHERE  l.vchTransNum = @TransNum
      GROUP BY l.vchTransNum , l.vchManufacturer, b.vchbrand

Open in new window

0
 

Author Closing Comment

by:dlavar
ID: 39885097
My solution was the one that worked and was most effective.
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

762 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