473,569 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need header values

How to get the header values in the sql with union.

For example,
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from dept
union
select empno,empname,' Employee','' from emp

I need output with
header:
dep dname loc mgr
1 mkt 4 34
2 sls 4 33
34 James Employee 45

Thank for your time.

Nov 12 '05 #1
5 1244

<hi****@gmail.c om> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
How to get the header values in the sql with union.

For example,
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from dept
union
select empno,empname,' Employee','' from emp

I need output with
header:
dep dname loc mgr
1 mkt 4 34
2 sls 4 33
34 James Employee 45

Thank for your time.


I was surprised that your query didn't work just the way it was so I tried
it and confirmed that it failed to put the desired headings at the top of
the columns in DB2 for Windows/Unix/Linux, Version 8 (Fixpack 8). (By the
way, I had to change to table names from 'emp' and 'dept' to 'employee' and
'department' so I assume you are on an older version of DB2 or on a
different operating system.)

I got the desired headings to appear by putting the 'as' expressions in
_both_ queries:
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from department
union
select empno as dep,lastname as dname,'Employee ' as loc,'' as mgr from
employee

Rhino
Nov 12 '05 #2
I tried my query with putting "as " in each of the select. Just putting
it on one select does not work.

Thanks Rhino.

Nov 12 '05 #3
You should specify same renamed column names explicitly for both SELECT
list.
For example,
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from dept
union
select empno as dep,empname as dname,'Employee ' as loc,'' as mgr from
emp

Nov 12 '05 #4
Tonkuma wrote:
You should specify same renamed column names explicitly for both SELECT
list.
For example,
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from dept
union
select empno as dep,empname as dname,'Employee ' as loc,'' as mgr from
emp


Alternatively you could do this:

SELECT *
FROM ( SELECT deptno, deptname, location, mgrno
FROM dept
UNION
SELECT empno, empname, 'Employee', ''
FROM emp ) AS t(dep, dname, loc, mgr)

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #5
Thanks Knut, that is a cool way of doing it..

Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2494
by: Don Seckler | last post by:
I am trying to set up a PHP web page so I can enter data into a database. I created a form: <form action="admin_news_insert_processor.php" method="post" name="frm_Insert_News" id="frm_Insert_News">
3
2200
by: Ron | last post by:
I need a way to read the hex values of an old DBase3 data file. Can anyone give me some info regarding how to grab hex values out of a file? Not sure exactly how to do this. Thanks for your help.
0
1086
by: Michael Rodriguez | last post by:
I have what I believe to be a typical master/detail scenario. I know how to use a transaction on the sql updates, but what about any dataset merges? My scenario goes like this: // call data layer to add new header record, get back auto-inc keys // call data layer to do all updates on detail tables, assign auto-inc keys from header where...
6
7062
by: Jason Collins | last post by:
There seems to be an inconsistency (bug?) in the way the Set-Cookie header is handled by the WebHeaderCollection. That is, the values of Set-Cookie, when an Expires is specified, contain the "," character. This seems to be incorrectly parsed during GetValues(). A simple example shows it best (there are 2 .aspx pages and an output): ...
0
1084
by: Evandro Klen S. Azeredo | last post by:
Hi, I'm with the folowing problem: I have two tables: header(id_header) and Itens(id_header, id_item). When I insert data in Itens table, this error is returned: "You cannot add or change a record because a related record is required in table 'header'." I'm using MS Access database.
2
2356
by: sheldonlg | last post by:
I have used the action= statement to send the form to a new page which can get the posted variables. I have used the header("Location: foo.php) statement after testing on the submit with isset. What I want to know is if they can be combined. That is, test first with the isset, and if no errors go to the action call. Simply going with...
8
31964
by: fredd00 | last post by:
hi i'm trying to change the gridview columns header text the columns are not auto generated, i have set specific headertext values for each column i want to change the header text based on the specific header text. i want to load a new text from a global resource file. what i'm actually trying to do and is not working :
6
1791
by: lokeanwolf | last post by:
Hi. I'm trying to create a basic template for a page, so that I can have the headers and footers stay the same, and only change the center content. I've already figured out how to do the includes part, but that requires I do that on every page on the site I am making. Is there a way I can have a single index page, which loads different...
4
7271
by: herbivore | last post by:
I am using curl to do a post request to a server. The request contains xml data, the standard post headers sent by curl do not work. I have tried using the custom_request option with the whole post request inside it, but then curl adds a header after the custom_request portion. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header); ^^^ the above...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.