Hi
Assume a query :
select bankno,regionno,officeno from afo
The above query displays three columns (grids) in query analyzer. Is there in any way that
we can concatenate the above three columns and display as only one column in the grid with a hyphen as separator.
ThanxTry:
select
convert(varchar,bankno) +
convert(varchar,regionno)+
convert(varchar,officeno)
from afo|||Or Even
select
convert(varchar,bankno) + '-' +
convert(varchar,regionno) + '-' +
convert(varchar,officeno)
from afo
convert(varchar(50),'I''m only any good with the easy ones' + ' - ' + 'lol')
GW|||kir441, be aware that when using convert(varchar,<table attribute>) you are converting to a varchar(30) datatype. While this is good enough for Integers it could cause truncation for other datatypes.
Nothing like the obveous GWilliy, but why didn't you use CAST?|||Paul & Gwilliy
I used convert(varchar,bankno) + '-' + convert(varchar,acctno) ...etc
for my query. It worked, as you suggested we can use CAST also.
Thanks for your answers.|||U Mean
CAST('I''m only any good with the easy ones' + ' - ' + 'lol' AS VarChar(50))
(notice the not so obvious in both methods ?)
Dunno really Paul -
Guess I'm just used to using Convert and it feels a little more english to me - not forgetting the ability to use the style option.
Is there a good reason why I should start using CAST instead ?
GW|||My philosophy is use what works and is most maintainable in your shop.
Thursday, February 16, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment