SQL2000 视图不支持UNION SQL 构造 替代方案 [ SQL | View | UNION ]
1. 先看在视图中使用union提示报的错:
2. 解决方案:表值函数+视图,例句:
SELECT LastName,FirstName,Title Employees
UNION
SELECT LastName,FirstName,Title Users
UNION
SELECT LastName,FirstName,Title Users
a). 建立表值函数:
CREATE FUNCTION dbo.FuncEmployeeAndUser()
RETURNS TABLE
AS
RETURN(
SELECT LastName,FirstName,Title Employees
UNION
SELECT LastName,FirstName,Title Users
)
RETURNS TABLE
AS
RETURN(
SELECT LastName,FirstName,Title Employees
UNION
SELECT LastName,FirstName,Title Users
)
b). 建立视图:
CREATE VIEW EmployeeAndUser AS
SELECT *
FROM FuncEmployeeAndUser()
SELECT *
FROM FuncEmployeeAndUser()
本文转自博客园农民伯伯的博客,原文链接:SQL2000 视图不支持UNION SQL 构造 替代方案 [ SQL | View | UNION ],如需转载请自行联系原博主。