Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Formatting Data

Author  Topic 

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2008-05-09 : 07:18:17

Hi,

I have a table as follows:

UserID FirstName LastName [ID]
-----------------------------------------
ID1 TestF1 TestL1 1
ID2 TestF2 TestL2 2
ID3 TestF3 TestL3 3

I would like to output the data as follows:

X_J001 | TestF1 | TestL1
X_J002 | TestF2 | TestL2
X_J003 | TestF3 | TestL3

where the first field is the concatenation of "X_J" followed by the formatting of the [ID] column with leading zeros when appropriate.

How do I do this?

Thanks in advance
Kabir

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-09 : 07:28:29
[code]select 'X_J' + right('00' + replace(UserID, 'ID', ''), 3), FirstName, LastName
from Table[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -