If the bill number is only needed for reporting or receipt printing and bill information isn't deleted then I wouldn't bother storing it.
If you derive then it you don't run the risk of accidentally writing the same number twice (or more times) to the DB nor do you have to reset a pre-assigned number if a bill doesn't get created when, for example, a customer complains and the manager writes off the cost by way of compensation.
A notional table...
create table bill
(
issueDate datetime not null
constraint df_bill_issued default getdate(),
issueDay as floor(cast(issueDate as float)),
totalNoTax decimal(5,2) not null,
taxRate decimal(3,2) not null
constraint df_bill_tax default(0)
)
Set up some noddy data...
insert into bill(issueDate, totalNoTax) values (getdate(), 0.75)
insert into bill(issueDate, totalNoTax) values (dateadd(hh, 1, getdate()), 1.50)
insert into bill(issueDate, totalNoTax) values (dateadd(hh, 2, getdate()), 2.50)
insert into bill(issueDate, totalNoTax) values (dateadd(hh, 3, getdate()), 3.50)
insert into bill(issueDate, totalNoTax) values (dateadd(hh, 4, getdate()), 4.50)
Write a query to get the bill information with a derived bill number..
set ANSI_WARNINGS OFF
select
count(counter.issueDay)+1 as billNumber,
bill.issueDate,
bill.totalNoTax,
bill.taxRate
from bill
left join (select issueDay, issueDate from bill) as counter
on counter.issueDay= bill.Issueday
and counter.issueDate < bill.IssueDate
group by
bill.issueDate,
bill.totalNoTax,
bill.taxRate
If you are going to be doing a lot of work where you need repeated access to bill number then consider converting the query to a view...
create view indexedBill
as
select
count(counter.issueDay)+1 as billNumber,
bill.issueDate,
bill.totalNoTax,
bill.taxRate
from bill
left join (select issueDay, issueDate from bill) as counter
on counter.issueDay= bill.Issueday
and counter.issueDate < bill.IssueDate
group by
bill.issueDate,
bill.totalNoTax,
bill.taxRate
...then pretend you've got a new table. For example...
select * from indexedBill where billNumber = 1
select * from indexedBill where issueDate < '18 september 2015 23:59:00'
And if you really must display a bill number when creating a new bill (why?) then a query along the following lines ought to be adequate if there isn't much concurrent bill creation.
select max(billNumber) + 1 from indexedBill
where issueDate = floor(cast(getdate() as float))