troubleshooting Question

SQL the column should return 1

Avatar of tanj1035
tanj1035 asked on
Microsoft SQL Server
2 Comments1 Solution74 ViewsLast Modified:
Hi Experts,

In my query, when column "acceptedtestdrive" is 0, the column "accepetedwithouttestdrivepercentage" returned 0 as well.
But the column "accepetedwithouttestdrivepercentage" should return 1 as 1-0 = 1.
Can you help me on it? Thanks.  

 select d.submittedtimestamp, 
 case when isnull(t.acceptedtestdrive,0) =0 then 0 else cast (t.acceptedtestdrive as float)/cast(count(d.dealid) as float ) end as accepetedtestdrivepercentage,
 case when isnull(t.acceptedtestdrive,0) =0 then 0 else 1- (cast (t.acceptedtestdrive as float)/cast(count(d.dealid) as float )) end as accepetedwithouttestdrivepercentage
  from [MMD_Feed].[dbo].[DealView] d
 left join #acceptedtestdrive t on d.submittedtimestamp= t.submittedtimestamp
  where d.dealstatus='sent'
  and d.alternatedeal='no'
  and d.manualdeal='no'
  and d.shopperaccepts>=1
  and cast(d.submittedtimestamp as date)>=@StartDate and cast(d.submittedtimestamp as date)<=@EndDate
  group by d.submittedtimestamp,t.acceptedtestdrive
  order by d.submittedtimestamp desc
ASKER CERTIFIED SOLUTION
awking00
Information Technology Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros