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)
 Select SSN but show with dashes

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-01-23 : 08:02:25
Joe writes "Greetings,

I have searched the Transact-SQL help file and have browsed this and other sites, but cannot find an answer to this.

I don't want to alter the data from the table - I just want to display the selected SSN in a more reader-friendly format. The data is in 555443333 format, but I want it to show as 555-44-3333.

Any way to do this in SQL Server 2000?

TIA,


Joe"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-23 : 08:12:47

Declare @SSN varchar(20)
set @SSN='555443333'
Select Left(@SSN,3)+'-'+Substring(@SSN,4,2)+'-'+Substring(@SSN,6,4) as SSN


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2006-01-23 : 09:39:29
Yup....BUT.....formatting for display should really handled by your reporting tool or user interface, not the database server.
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-01-23 : 10:09:02
just to be different

Declare @SSN varchar(20)
set @SSN='555443333'
Select stuff(stuff(@SSN,6,0,'-'),4,0,'-') as SSN

Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-24 : 00:41:34
Good to see you back Stuff Specialist

Is Relocation over?



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2006-01-24 : 10:59:47
Thanks! Still working on the migration of servers and what not, but I am all moved in to my new house. I still don't have a good internet option though

I've also been playing a bit o' chess on redhotpawn.com as well... can be distracting

Corey

Co-worker on children "...when I have children, I'm going to beat them. Not because their bad, but becuase I think it would be fun ..."
Go to Top of Page
   

- Advertisement -