July 17, 2007 at 6:39 am
Hello All,
I have a temp table with a column which needs to be formattted. The column has following values:
2.0\ABC
1.4
1.2\PQR
2.2\XYZ
1.1
I need to format this column as
2.0(ABC)
1.4
1.2(PQR)
2.2(XYZ)
1.1
If there is a backslash then the string followed by that showed appear in parenthesis.
Can anyone tell me how to do it?
Thanks in advace.
July 17, 2007 at 7:54 am
Thanks for the quick reply Jeremy.
I am already parsing the string to get these strings. The actual values in the database column 'columnID' are
\\CDR\HR Project\GMP 2.0\ABC
\\CDR\HR Project\GMP 1.4
\\CDR\HR Project\GMP 1.2\PQR
\\CDR\HR Project\GMP 2.2\XYZ
\\CDR\HR Project\GMP 1.1
I use the following sql
select replace(columnID,left(columnID,charindex('.',columnID)-2),'') AS IDPath
which parses to
2.0\ABC
1.4
1.2\PQR
2.2\XYZ
1.1
But now I need as final output
2.0(ABC)
1.4
1.2(PQR)
2.2(XYZ)
1.1
How would I combine your suggestion to my earlier parse function to get the final output
Thanks in advance
July 17, 2007 at 8:07 am
just nest your replace into mine:
declare @t table
( columnId varchar(255))
insert @t select '\\CDR\HR Project\GMP 2.0\ABC'
insert @t select '\\CDR\HR Project\GMP 1.4'
insert @t select '\\CDR\HR Project\GMP 1.2\PQR'
insert @t select '\\CDR\HR Project\GMP 2.2\XYZ'
insert @t select '\\CDR\HR Project\GMP 1.1'
select replace(replace(columnId,left(columnId,charindex('.',columnId)-2),''), '\', '(')
+ case
when charindex('\', replace(columnId,left(columnId,charindex('.',columnId)-2),'')) > 0 then ')'
else ''
end
from @t
J
July 17, 2007 at 1:05 pm
Thanks Jeremy, you suggestion worked exactly the way I wanted it to be.
Thanks again
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply