如何在SQL中保存Union [英] how to save Union in SQL

查看:96
本文介绍了如何在SQL中保存Union的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在SQL中保存Union,以便可以将其与Dropdownlist链接?请帮助

这是我的联合声明

从ECD中选择区ID,ECD名称
UNION
从学校中选择DistrictID,学校名称

另存为在storprocedures,视图,表下将其存储在SQL中的位置.

How can I save Union in SQL so that I can link it with a Dropdownlist? pls help

This is my Union Statement

SELECT DistrictID,ECDName FROM ECD
UNION
SELECT DistrictID,SchoolName FROM Schools

save as in where do you store it in SQL under storprocedures, view, tables.where?

推荐答案

您可以使用视图,如下所示:

You could use a View, something like this:

CREATE VIEW [Your_View_Name]
AS
SELECT DistrictID, ECDName as Name FROM ECD
UNION
SELECT DistrictID, SchoolName as Name FROM Schools



它存储在视图"下.



It is stored under Views.


MBalentle,

我认为将其转换为StoredProcedure更好,因为如果需要进行一些过滤,则可以将一些参数传递给该存储过程,然后将该存储过程调整为新要求.
Hi MBalentle,

In my opinion converting it to a StoredProcedure is better because if the need for some filtering arises you can simply pass some parameters to that stored procedure and adapt that storedprocedure to the new requirements.


创建视图temp

create view temp
as
SELECT DistrictID,ECDName FROM ECD
UNION
SELECT DistrictID,SchoolName FROM Schools



这篇关于如何在SQL中保存Union的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆