Hi.
I wasn't expecting to be that complicated or I'm missing something.
I want to get the percentage of reserved vs unreserved.
So the tables has:
Barcode , Vtype, Isreserved
1111111,1,0
1111113,1,1
1111112,1,2
2111115,2,1
2111116,2,0
2111118,2,1
etc
The full select would be :
SELECT [BarCode]
,[VType]
,[IsReserved]
FROM [tblOPVoucher]
What I'm trying as a result is this:
Vtype,PercentageReserverd,Percentagenoreserved
1,88,22
2,16,84
I can't even do the first calculation , it will bring out zero.
select [VType], ( (select count(*) from [[tblOPVoucher] where VType=1)-(select count(*)
from [tblOPVoucher] where VType=1 and IsReserved =1) ) / (select count(*) from [tblOPVoucher] where VType=1) * 100 as T1
FROM [tblOPVoucher]
group by VType
this will give
VType T1
1 0
2 0
select [VType], ( (select count(*) from [tblOPVoucher] where VType=1)-(select count(*)
from [tblOPVoucher] where VType=1 and IsReserved =1) )
FROM [tblOPVoucher]
group by VType
This will give:
VType (No column name)
1 999
2 999
So I was expecting a 99 .
So is there a problem here with the calculations? Must I declare a double somewhere? Is there a better approach?
Thanks.