473,287 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

How to specify column header titles in a SQL CREATE TABLE statement?

When I write a create table SQL statement I want to add some information about the column heading of each column.
How does the exact syntax for the create table look like (which includes this column data look)?

How do I add later column headings ?

Tom

Jul 19 '05 #1
4 21303

"Thomas Jerkins" <to*****@hotmail.com> wrote in message
news:ck*************@news.t-online.com...
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column data look)?
How do I add later column headings ?


I am assuming that you are using the phrase 'column heading' to mean the
title that appears above a column when you run an SQL Select from the DB2
command line or in the DB2 Command Center. For example, given:

select lastname, salary
from employee
where empno in ('000010', '000020');

results in:

LASTNAME SALARY
------------ ---------
HAAS 52750.00
THOMPSON 41250.00

I assume that your question refers to 'LASTNAME' and 'SALARY' in this result
and that you want to control what these headings are. If that's NOT what you
mean by 'column headings', please clarify.

It is possible that SQLServer, Oracle and DB2 handle these column headings
the same way as a result of complying with the same standards. Then again,
they may not not; I am only answering with respect to DB2.

The Create Table statement does not have any effect on the column heading
that appears when you query the table. To control the column heading, you
use an 'as' expression within the Select statement. For example:

select lastname as Employee_Last_Name, salary as Employee_Pay
from employee
where empno in ('000010', '000020');

results in:

EMPLOYEE_LAST_NAME EMPLOYEE_PAY
--------------------------- ------------------
HAAS 52750.00
THOMPSON 41250.00

If you want embedded blanks within the column heading, you need to embed the
column heading within quotes. For example:

select lastname as "Employee Last Name", salary as "Employee Pay"
from employee
where empno in ('000010', '000020');

results in

EMPLOYEE LAST NAME EMPLOYEE PAY
-------------------------- -----------------
HAAS 52750.00
THOMPSON 41250.00

[Please note that I "took some liberties" with the result sets shown in
these examples due to the proportional fonts used in my newsreader. In the
real world:
- the lastname values will be left-justified under the LASTNAME heading
- the salary values will be right-justified under the SALARY heading.
- the headings will always be uppercase if the query is executed in the DB2
command line but will match the case of the query if the query is executed
in the Command Center]

Rhino
Jul 19 '05 #2
Rhino wrote:
If you want embedded blanks within the column heading, you need to embed the
column heading within quotes. For example:

select lastname as "Employee Last Name", salary as "Employee Pay"
from employee
where empno in ('000010', '000020');

results in

EMPLOYEE LAST NAME EMPLOYEE PAY
-------------------------- -----------------
HAAS 52750.00
THOMPSON 41250.00

[Please note that I "took some liberties" with the result sets shown in
these examples due to the proportional fonts used in my newsreader. In the
real world:
- the lastname values will be left-justified under the LASTNAME heading
- the salary values will be right-justified under the SALARY heading.
- the headings will always be uppercase if the query is executed in the DB2
command line but will match the case of the query if the query is executed
in the Command Center]


Headings specified in the "as" clause will be used EXACTLY AS RECEIVED
by the DB2 command processor. If you are getting folding to upper case
then you are most likely not correctly specifying the column headings.

Under RHEL3, UDB 8.1 FP7:

db2 "select lastname as ""Lastname"" from employee where lastname like 'L%'"

LASTNAME
---------------
LUCCHESSI
LUTZ
LEE

appears correct and returns the data but does not have the correct
column heading! The operating system command line processor gets this
long before DB2 does and alters it.

db2 "select lastname as \"Lastname\" from employee where lastname like 'L%'"

Lastname
---------------
LUCCHESSI
LUTZ
LEE

yields exactly the results that are expected.
Phil Sherman

Jul 19 '05 #3

"Philip Sherman" <ps******@ameritech.net> wrote in message
news:Tk*****************@newssvr31.news.prodigy.co m...
Rhino wrote:
If you want embedded blanks within the column heading, you need to embed the column heading within quotes. For example:

select lastname as "Employee Last Name", salary as "Employee Pay"
from employee
where empno in ('000010', '000020');

results in

EMPLOYEE LAST NAME EMPLOYEE PAY
-------------------------- -----------------
HAAS 52750.00
THOMPSON 41250.00

[Please note that I "took some liberties" with the result sets shown in
these examples due to the proportional fonts used in my newsreader. In the real world:
- the lastname values will be left-justified under the LASTNAME heading
- the salary values will be right-justified under the SALARY heading.
- the headings will always be uppercase if the query is executed in the DB2 command line but will match the case of the query if the query is executed in the Command Center]
Headings specified in the "as" clause will be used EXACTLY AS RECEIVED
by the DB2 command processor. If you are getting folding to upper case
then you are most likely not correctly specifying the column headings.

Under RHEL3, UDB 8.1 FP7:

db2 "select lastname as ""Lastname"" from employee where lastname like

'L%'"
LASTNAME
---------------
LUCCHESSI
LUTZ
LEE

appears correct and returns the data but does not have the correct
column heading! The operating system command line processor gets this
long before DB2 does and alters it.

db2 "select lastname as \"Lastname\" from employee where lastname like 'L%'"
Lastname
---------------
LUCCHESSI
LUTZ
LEE

yields exactly the results that are expected.

I stand corrected; my column headings were coming out upper case on the
command line because I had not quoted them correctly.

However, I don't get quite the same results that you did from your two
queries. I am running DB2 V7.2.7 on Windows XP.

Given:
db2 "select lastname as ""Lastname"" from employee where lastname like 'L%'"

I get the following when I execute it on the DB2 command line:
SQL0100N The string constant beginning with ""Lastname from employee where
lastname like 'L%'" does not have an ending string delimiter. SQLSTATE=42603

I can eliminate this error by putting *three* consecutive quotes after the
alias, i.e.
db2 "select lastname as ""Lastname""" from employee where lastname like
'L%'"

This results in:
Lastname
-----------
LUCCHESSI
LUTZ
LEE

as you predicted.

However, when I execute (on the DB2 command line):
db2 "select lastname as \"Lastname\" from employee where lastname like 'L%'"

I get:
Lastname
-----------
LUCCHESSI
LUTZ
LEE

just as you described.

In any case, the original poster probably knows more now about column
headings that he really wanted to know ;-)

Rhino
Jul 19 '05 #4
Rhino wrote:
However, I don't get quite the same results that you did from your two
queries. I am running DB2 V7.2.7 on Windows XP.

Given:
db2 "select lastname as ""Lastname"" from employee where lastname like
'L%'"

I get the following when I execute it on the DB2 command line:
SQL0100N The string constant beginning with ""Lastname from employee where
lastname like 'L%'" does not have an ending string delimiter.
SQLSTATE=42603

I can eliminate this error by putting *three* consecutive quotes after the
alias, i.e.
db2 "select lastname as ""Lastname""" from employee where lastname like
'L%'"

This results in:
Lastname
-----------
LUCCHESSI
LUTZ
LEE

as you predicted.

However, when I execute (on the DB2 command line):
db2 "select lastname as \"Lastname\" from employee where lastname like
'L%'"

I get:
Lastname
-----------
LUCCHESSI
LUTZ
LEE

just as you described.

In any case, the original poster probably knows more now about column
headings that he really wanted to know ;-)


You might want to look at the documentation for the DOS command prompt (or
whatever you use) to figure out what it does with the quotes. A Unix
shell, given

"abc \" def"

will pass the following string to the application

abc " def

The DOS command prompt works on the parameters as well somehow, and you have
to counter that to get the " to DB2.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Jul 19 '05 #5

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

Similar topics

0
by: Morten Gulbrandsen | last post by:
Hi Programmers, after this legal statement ALTER TABLE EMPLOYEE TYPE =3D InnoDB; I get=20 Warnings: 0 =20 and still MySQL claims to have to use Type =3D MyISAM,
4
by: Thomas Jerkins | last post by:
When I write a create table SQL statement I want to add some information about the column heading of each column. How does the exact syntax for the create table look like (which includes this column...
2
by: Irfan Bondre | last post by:
When I try to create a table with a vargraphic column I get the following error. CREATE TABLE EIITEST.IRFAN ("VARC" VARCHAR (48) , "VARGRA" VARGRAPHIC (96) ) DATA CAPTURE NONE IN USERSPACE1;...
10
by: Colleyville Alan | last post by:
I am trying to turn a short and fat (63 columns) table into one that is tall and skinny (7 columns). Basically, I am trying to create a "reverse crosstab" using a looping structure in VBA along...
3
by: Meena | last post by:
Hi Every Body, I have created a crystal Report and linked to my vb.net forms and working fine, I added more drill drowns in groups everything fine, but What I need is I am not able to display...
3
by: appearinggalaxy | last post by:
How can I change the column header text in windows form datagrid? *-----------------------* Posted at: www.GroupSrv.com *-----------------------*
2
by: ricky | last post by:
Hello, If anyone could help me with this I would highly appreciate it. I've tried everything and nothing works. What I am trying to do is so damn basic and it's just frustrating that it seems...
37
by: Jan Wagner | last post by:
Hi, can't figure this one out, what's the CSS way to specify the language? In HTML it would be simply an lang="xx" attribute, or XHTML xml:lang="xx", but, how about in CSS? This would be...
3
by: shawrie | last post by:
Hello everyone can anyone please help me? I basically want to set the length of a string variable to help spacing my simple report out. i tried dim test as string(14) but it didnt like that
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

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.