Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

What will be the Query?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
Amolondhe007
Warnings : 1

New User


Joined: 16 Apr 2007
Posts: 50
Location: Pune

PostPosted: Wed Feb 25, 2009 4:34 pm    Post subject: What will be the Query?
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: 456
Location: Belgium

PostPosted: Wed Feb 25, 2009 4:45 pm    Post subject:
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    Post subject:
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:
http://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    Post subject:
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:
http://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    Post subject: Re: What will be the Query?
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

Site Director


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

PostPosted: Thu Feb 26, 2009 12:31 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject: Reply to: What will be the Query?
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Omegamon for DB2 query ashek15 DB2 0 Wed Feb 15, 2017 11:25 am
No new posts Query on DB2 WLM stored procedures ashek15 DB2 8 Sun Feb 12, 2017 11:13 pm
No new posts GETMAIN/FREEMAIN query Suja.Sai CICS 9 Tue Jan 31, 2017 12:01 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us