SQL2000 views do not support the union SQL constructor [SQL | View | UNION]

Source: Internet
Author: User

 

Preface

Database view is a commonly used function. During the use process, you may occasionally need to UNION multiple tables. Here is a reference solution. Please refer to the text.

 

Environment

1. Microsoft SQL Server 2000 sp3

 

Body

1. First, the following error is reported when union is used in the View:

2. Solution: Table valued functions + views. Example:

SELECT LastName, FirstName, Title Employees
UNION
SELECT LastName, FirstName, Title Users

A). Create a table value function:

Create function dbo. FuncEmployeeAndUser ()
RETURNS TABLE
AS
RETURN (
SELECT LastName, FirstName, Title Employees
UNION
SELECT LastName, FirstName, Title Users
)

B). Create a view:

Create view EmployeeAndUser
SELECT *
FROM FuncEmployeeAndUser ()

 

End

Although a little troublesome, it is one of the solutions to such problems.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.