我想在运行查询时将我自己的列添加到我的输出中的两个现有列(Tickets和Request Date)。
代码:
select f02_ticket_number as 'Tickets', f02_requested_date as 'Request
date'
from client_uli_zendesk_ticket
left outer join co_customer on f02_cst_key=cst_key
left outer join co_individual_ext on cst_key=ind_cst_key_ext
left join co_individual on ind_cst_key_ext=ind_cst_key
where f02_status<>'deleted'
输出:
Tickets Request Date
1 5/8/2017
2 4/19/2017
这就是我想要的样子:
Tickets Request Date My added column
1 5/8/2017 May/2017
2 4/19/2017 April/2017
3 6/19/2017 June/2017
4 7/19/2018 July/2018
5 8/19/2018 August/2018
我理解我会编写一个case语句来将请求Date分类到我的新列中,但是,我不知道如何通过select语句添加我的新列,包括正确的数据类型。 有人可以帮忙吗?
答案 0 :(得分:0)
您可以这样做:
select f02_ticket_number as Tickets, f02_requested_date as [Request
date],
datename(month, f02_requested_date) + '/' + datename(year, f02_requested_date)
from . . .;
这假设您的国际化设置设置为英语。
答案 1 :(得分:0)
尝试类似
的内容select f02_ticket_number as 'Tickets', f02_requested_date as 'Request date', CONVERT(CHAR(4), f02_requested_date, 100) + CONVERT(CHAR(4), f02_requested_date, 120) AS 'Your Added Column name'
from client_uli_zendesk_ticket
left outer join co_customer on f02_cst_key=cst_key
left outer join co_individual_ext on cst_key=ind_cst_key_ext
left join co_individual on ind_cst_key_ext=ind_cst_key
where f02_status<>'deleted'