2
我想弄清楚如何將學生年齡轉換爲年齡+月份。因此,例如,如果學生的出生日期爲1/1/2000,則學生年齡將顯示爲:16和6個月年齡格式 - 年和月
我能夠對查詢進行腳本編寫,以便學生年齡顯示爲整數,但是不知道如何包括幾個月。我需要改變什麼?
ALTER procedure [dbo].[RP_Student_Attendance] (@perf_code varchar(10))
as
-- set @perf_code = '3496A'
SELECT
i.short_name,
i.text1 as perf_desc,
i.text2 perf_dates,
i.text3 perf_times,
p.perf_no,
h.[Role],
h.customer_no,
c.sex, b.birthday,
g.grade_level,
--(DATEDIFF(yy,b.birthday,GETDATE())) as student_age,
student_age = CASE
WHEN dateadd(year, datediff (year, b.birthday, GETDATE()),b.birthday) > GETDATE()
THEN datediff (year, b.birthday, GETDATE()) - 1
ELSE datediff (year, b.birthday, GETDATE())end,
c.fname + ' ' + c.lname as student_name
FROM T_INVENTORY i
JOIN T_PERF p on i.inv_no = p.perf_no
JOIN T_TICKET_HISTORY h on p.perf_no = h.perf_no and [Role] = 4
JOIN T_CUSTOMER c on h.customer_no = c.customer_no
LEFT JOIN (select customer_no, key_value as birthday from TX_CUST_KEYWORD where keyword_no = 1) b on c.customer_no = b.customer_no
LEFT JOIN (select customer_no, key_value as grade_level from TX_CUST_KEYWORD where keyword_no = 428) g on c.customer_no = g.customer_no
WHERE p.perf_code = @perf_code