hi
i am using sql server 2005.
i have table
tbl_cashcounter
CREATE TABLE [dbo].[tbl_CompanyMaster]( [CompanyID] [int] NOT NULL, [Name] [nvarchar](100) NULL, [YearStart] [datetime] NULL, [YearEnd] [datetime] NULL, ) this table has always only one row
CompanyIDName YearStart YearEnd
2 Fotofash Color Lab & Studio2014-04-01 12:00:00.0002015-03-31 23:55:49.000CREATE TABLE [dbo].[tbl_CashCounter]( [Id] [int] IDENTITY(1,1) NOT NULL, [BillNo] [nvarchar](50) NULL, [BillDate] [datetime] NULL )
there is Bill Format
strar yeear ( 14) endyear(15) department serial No.
yyyyDp-xxxxxx1
1415-vd-000001
1415-vd-000002
1415-ST-000001
1415-ST-000002
i am looking sql function which will return max number between YearStart andYearend with respect department
i have witten the query
select MAX(Right(BillNo,6)) AS no from tbl_CashCounter,tbl_companymaster WHERE (SUBSTRING(BillNo, 5, 2)) = 'vd' and billdate between yearstart and yearend
but it's not working.
please help me.
note : i am using sqlserver 2005
Thanks Best Regard Naweez