查询:
SELECT TOP (1) '-1' AS hrempid, 'All employees' AS fullname
FROM employee
UNION
SELECT fullname, hrempid
FROM employee AS employee1
order by fullname
错误: 将数据类型varchar转换为bigint时出错。
答案 0 :(得分:4)
union
之后,您的列的顺序错误。这是更正版本:
SELECT TOP (1) '-1' AS hrempid, 'All employees' AS fullname
FROM employee
UNION
SELECT hrempid, fullname
FROM employee AS employee1
ORDER BY fullname
更好的是,使用这样的东西:
SELECT CAST(-1 AS BIGINT) AS hrempid, 'All employees' AS fullname
UNION ALL
SELECT hrempid, fullname
FROM employee AS employee1
ORDER BY fullname
答案 1 :(得分:1)
将'
保留在hrempid
周围并切换列。试试这个:
SELECT TOP (1) 'All employees' AS fullname, -1 AS hrempid
FROM employee
UNION
SELECT fullname, hrempid
FROM employee AS employee1
order by fullname