I want to know how can I get the year and month into my database. For example, suppose it’s August, 2011. The output that I need is like this: CAB 11 08 001
(CA
It looks like you're making separate columns for YEAR, MONTH, etc.
Most (all?) DBMSs I'm aware of have a Date
type. Use it. They put a lot of useful stuff in it, like accepting date inputs in different formats and giving them as output in pretty much any format you can think of.
For example, if you have a DT
column of type Date
in Oracle, you can output month as
SELECT TO_CHAR(DT, "MM") FROM MYTABLE;
and the month will always be displayed as 2 digits (01, 02, ... 12)
SELECT
'CAB'
+ RIGHT(YEAR(GetDate()),2)
+ RIGHT('0' + CONVERT(VARCHAR, MONTH(GetDate())),2)
+ Right('00000' + Cast(CurrentNo as varchar(10)), 5)
That might work..
Using your method \ logic..
Right('0' + Cast(Month(GetDate()) as varchar(10)),2)