We help IT Professionals succeed at work.

SQL the column should return 1

tanj1035
tanj1035 asked
on
65 Views
Last Modified: 2015-07-06
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

Open in new window

Comment
Watch Question

Mike EghtebasDatabase and Application Developer

Commented:
re> But the column "accepetedwithouttestdrivepercentage" should return 1 as 1-0 = 1

at:  ... else 1- (cast (t.acceptedtestdrive as float)/cast(count(d.dealid) as float )) end as

it could be else 1- 1 ... end as thus prodicing 0
Information Technology Specialist
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.