SQL the column should return 1

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

tanj1035Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mike EghtebasDatabase and Application DeveloperCommented:
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
awking00Information Technology SpecialistCommented:
case when isnull(t.acceptedtestdrive,0) =0 then 1 else 1- (cast (t.acceptedtestdrive as float)/cast(count(d.dealid) as float )) end as accepetedwithouttestdrivepercentage

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.