我有以下查询:
SELECT '-SELECT MONTH' NAME, -1 VALUE
UNION ALL SELECT 'JANUARY' NAME,1 VALUE
UNION ALL SELECT 'FEBRUARY' NAME,2 VALUE
UNION ALL SELECT 'MARCH' NAME,3 VALUE
UNION ALL SELECT 'APRIL' NAME,4 VALUE
UNION ALL SELECT 'MAY' NAME,5 VALUE
UNION ALL SELECT 'JUNE' NAME,6 VALUE
UNION ALL SELECT 'JULY' NAME,7 VALUE
UNION ALL SELECT 'AUGUST' NAME,8 VALUE
UNION ALL SELECT 'SEPTEMBER' NAME,9 VALUE
UNION ALL SELECT 'OCTOBER' NAME,10 VALUE
UNION ALL SELECT 'NOVEMBER' NAME,11 VALUE
UNION ALL SELECT 'DECEMBER' NAME,12 VALUE
我绑定到下拉列表。
我有另一个查询
SELECT MONTH FROM HRMONTHYEARMASTER
WHERE LOCKINGSTATUS IS NULL OR LOCKINGSTATUS <> '05'
这给了我特别的几个月。
我的问题是我想要合并这两个查询,并在结果集中只获取月份名称及其值。 我不知道如何去做。请帮忙..
答案 0 :(得分:0)
对于union,您必须具有相同的列名:
SELECT '-SELECT MONTH' NAME, -1 VALUE
UNION ALL SELECT 'JANUARY' NAME,1 VALUE
UNION ALL SELECT 'FEBRUARY' NAME,2 VALUE
UNION ALL SELECT 'MARCH' NAME,3 VALUE
UNION ALL SELECT 'APRIL' NAME,4 VALUE
UNION ALL SELECT 'MAY' NAME,5 VALUE
UNION ALL SELECT 'JUNE' NAME,6 VALUE
UNION ALL SELECT 'JULY' NAME,7 VALUE
UNION ALL SELECT 'AUGUST' NAME,8 VALUE
UNION ALL SELECT 'SEPTEMBER' NAME,9 VALUE
UNION ALL SELECT 'OCTOBER' NAME,10 VALUE
UNION ALL SELECT 'NOVEMBER' NAME,11 VALUE
UNION ALL SELECT 'DECEMBER' NAME,12 VALUE
UNION ALL
SELECT MONTH AS NAME, 100 AS VALUE FROM HRMONTHYEARMASTER
WHERE LOCKINGSTATUS IS NULL OR LOCKINGSTATUS <> '05'
答案 1 :(得分:0)
SELECT MONTH VALUE,DATENAME(month, DATEADD(month, MONTH-1, CAST('2008-01-01' AS datetime))) NAME
FROM HRMONTHYEARMASTER
WHERE LOCKINGSTATUS IS NULL OR LOCKINGSTATUS <> '05'
这解决了我的问题。现在我得到了Name和一个月的int值。
谢谢大家!!!!