IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

What will be the Query?


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Amolondhe007
Warnings : 1

New User


Joined: 16 Apr 2007
Posts: 49
Location: Pune

PostPosted: Wed Feb 25, 2009 4:34 pm
Reply with quote

Hi,

Supposed i have one Table - Emplyoee
It has two Columns- First Name and Last Name.

And See Table Format as below:

Code:
First name     Last Name
Amol           asa
Vishal         dfgg
Manoj          dgsdf
Ajay           dfg
Nitin          sfasf


Now I want the Ouput as:

Code:
Amol asa
Vishal dfgg
Manoj dgsdf
Ajay dfg
Nitin sfasf

What will be the SQL query for this?
Back to top
View user's profile Send private message
PeD

Active User


Joined: 26 Nov 2005
Posts: 459
Location: Belgium

PostPosted: Wed Feb 25, 2009 4:45 pm
Reply with quote

Can't you read the SQL Reference manual for such difficult query?

See on top IBM Manuals
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Feb 25, 2009 4:46 pm
Reply with quote

do you want to concatenate two columns into one host variable?

what is your desired sort order? sorry, I was unable to determine the sort order
based on your example.

and please use the '[' code /code ']' tags, here is the URL:
ibmmainframes.com/faq.php?mode=bbcode
Back to top
View user's profile Send private message
jaspal

New User


Joined: 22 May 2007
Posts: 68
Location: mumbai

PostPosted: Wed Feb 25, 2009 8:09 pm
Reply with quote

dbzTHEdinosauer wrote:
do you want to concatenate two columns into one host variable?

what is your desired sort order? sorry, I was unable to determine the sort order
based on your example.

and please use the '[' code /code ']' tags, here is the URL:
ibmmainframes.com/faq.php?mode=bbcode
Back to top
View user's profile Send private message
jaspal

New User


Joined: 22 May 2007
Posts: 68
Location: mumbai

PostPosted: Wed Feb 25, 2009 8:21 pm
Reply with quote

Hi ,

Sorry for the previous post TYPO error:

Below query would give the required output:
Quote:
select first name ||' '|| last name from emp table ;

Use where clause if required.

Thanks.
Jaspal
919923696840
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Feb 26, 2009 12:31 am
Reply with quote

Hello,

Did you test this before posting? I believe this will return more spaces than are wanted. . .
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Feb 26, 2009 12:04 pm
Reply with quote

Amol,
Please try this.

Code:
select STRIP(first_name) ||' '|| STRIP(last_name) from emp table ;
Back to top
View user's profile Send private message
jaspal

New User


Joined: 22 May 2007
Posts: 68
Location: mumbai

PostPosted: Thu Feb 26, 2009 5:13 pm
Reply with quote

Hi Srihari,

If you would run the below queries you will get same output:

Code:
Q1: select first name ||' '|| last name from emp table ;
Q2: select STRIP(first_name) ||' '|| STRIP(last_name) from emp table ;

I am bit curious to know why you suggested to STRIP the name........?
I would really appreciate your response.

as per my understanding ,STRIP function removes blanks or another specified character from the end, the beginning, or both ends of a string expression.
Syntax: STRIP (String EXP,Leading/Trailing/Both,Strip Character);
Assume that the host variable BALANCE of type CHAR(9) has a value of '000345.50'.

Q3:
Code:
SELECT STRIP(:BALANCE, LEADING, '0'),
       FROM emp table


Output : Returns the value '345.50'.

Secondly,

If we will run the below query it will take a singe blank space:
Code:
Select first name ||' '|| last name from emp table ;
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Thu Feb 26, 2009 6:05 pm
Reply with quote

jaspal wrote:

If we will run the below query it will take a singe blank space:
Code:
Select first name ||' '|| last name from emp table ;


What if first name and last name are loaded into the table with with trailing or leading spaces? If first name is a char(15) column with a value of 'JOHN' then your query will have more than 1 spaces between the first and last names!
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Thu Feb 26, 2009 6:07 pm
Reply with quote

Assuming First_name is of CHAR(10)
Results without STRIP
Code:
Amol       asa
Results with STRIP
Code:
Amol asa

Hope it helps,
WTF
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts RC query -Time column CA Products 3
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Issue with EXEC CICS QUERY SECURITY c... CICS 6
Search our Forums:

Back to Top