Click here to Skip to main content
12,449,902 members (39,690 online)
Rate this:
 
Please Sign up or sign in to vote.
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?
Posted 28-Nov-11 4:24am
Updated 28-Nov-11 18:58pm
v3
Comments
Amir Mahfoozi 28-Nov-11 11:46am
   
What your union statement is? Please provide it.
Eduard Lu 29-Nov-11 0:48am
   
define save
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
Marcus Kramer 30-Nov-11 15:02pm
   
+5. Absolutely correct.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

create view temp
as
SELECT DistrictID,ECDName FROM ECD
UNION
SELECT DistrictID,SchoolName FROM Schools
  Permalink  
Comments
Marcus Kramer 30-Nov-11 15:02pm
   
Sorry, but create a temp view is a huge waste of resources for this. Solution 1 is the correct way to deal with this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 30 Nov 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100