我想以 MON / Serial_No 格式显示优惠券号码。 我有保存在表格中的凭证日期,我想从凭证日期显示月份,并使用序列号显示 优惠券无格式
例如: 如果JAN月有5条记录,则显示JAN / 1,JAN / 2,JAN / 3,JAN / 4,JAN / 5 如果FEB月有3条记录,则显示FEB / 1,FEB / 2,FEB / 3
这是我的代码/查询
SELECT
UPPER(LEFT(DATENAME(MONTH, Cust_Payment.Date_Of_Payment), 3)) as
'Voucher_No',
Cust_Payment.Date_Of_Payment as 'Voucher_Date'
from Customer_Payments Cust_Payment
请帮忙。 提前谢谢。
答案 0 :(得分:3)
试试这个
SELECT
(
UPPER(LEFT(DATENAME(MONTH, Cust_Payment.Date_Of_Payment), 3)) +
'/' +
CONVERT(varchar(10),row_number() over (partition by MONTH(Cust_Payment.Date_Of_Payment) order by Cust_Payment.Date_Of_Payment))
)as 'Voucher_No',
Cust_Payment.Date_Of_Payment as 'Voucher_Date'
from Customer_Payments Cust_Payment
答案 1 :(得分:1)
试试这个
(UPPER(LEFT(DATENAME(MONTH, Cust_Payment.Date_Of_Payment), 3)) +'/' +
CONVERT(varchar(10),row_number() over (partition by MONTH(Cust_Payment.Date_Of_Payment) order by Cust_Payment.Date_Of_Payment)))as 'Voucher_No2',