aspose file tools*
The moose likes JDBC and the fly likes concatination of 3 fields in SQL query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "concatination of 3 fields in SQL query" Watch "concatination of 3 fields in SQL query" New topic
Author

concatination of 3 fields in SQL query

syam ganna
Greenhorn

Joined: Nov 04, 2004
Posts: 10
Hi Guyz,
i wanted to concatenate 3 fields and display the result. but concat() is taking only two fields as parameter. i want to concat first_name,last_name,mid_name.
can any body suggest answer for it.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
better do it in your code instead.
dont know for other databases. in oracle we use pipleline to concat.
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
select concat(concat(f_name,m_name),l_name) from table_name where ....


Hope it helps
Beksy
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi,
I prefer to do this in application side and not in sql query.
But if you want to do this, you can use like this



Correct me if I am wrong
Hope this help

daniel
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

I will prefer to use StringBuffer as using concat on String should be avoided.



Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi Shailesh,
I dont understand about your query...



According to my experience, there is no keyword StringBuffer in SQL keywords.
StringBuffer is Java object and we cannot mix that into our sql query.

I think we can use StringBuffer to compose that name in application side.
After we receive ResultSet, we can get first_name, mid_name and last_name.
And then using StringBuffer to compose that value...

Correct me if I am wrong to understand your words
thanks
daniel
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by Fisher Daniel:
Hi Shailesh,
I dont understand about your query...

According to my experience, there is no keyword StringBuffer in SQL keywords.



daniel

I think We both are on different frame....
as adeel said
better do it in your code instead.

So my reply was in same context

and I was suggesting to make a query in code



However It was mistake that after seeing your query I interpreted that same is being formed in Java. sorry for my mistake
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Shailesh Chandra:


Actually, what i was trying to say is something totally different.
Use of concat() function or pipelines might be database specific or somehow differs among databases. might be.

thats why i said better do it in your code. it means just simply query the db like this,

then in you code do this,


cheers.
syam ganna
Greenhorn

Joined: Nov 04, 2004
Posts: 10
O.K. Thanks Guys.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: concatination of 3 fields in SQL query