This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

concatination of 3 fields in SQL query

 
syam ganna
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
better do it in your code instead.
dont know for other databases. in oracle we use pipleline to concat.
 
Beksy Kurian
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
select concat(concat(f_name,m_name),l_name) from table_name where ....


Hope it helps
Beksy
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will prefer to use StringBuffer as using concat on String should be avoided.

 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O.K. Thanks Guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic