Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting number 1

Status
Not open for further replies.

Bluejay07

Programmer
Joined
Mar 9, 2007
Messages
780
Location
CA
Hello,

Just a small question.

In a query, how do I format a string of numbers. For example, if the table has the value '123456789', what command should I use to get the result in the following format: '123-45-6789'

Thanks.
 
Select Stuff(Stuff('123456789', 6,0, '-'), 4, 0, '-')

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Formatting the value is your FRONTEND job!!!!
How do you display the value is NOT a job for the SQL Server.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Oh man! I should have just said, "GO STUFF YOUR DATA!". Maybe I wouldn't have gotten yelled at by Boris. [cry]

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Hi George,

Thank you very much for your reply. Your statement does work if that is the only field in the query. As soon as I add it with the rest of my query, I get
Msg 8152, Level 16, State 14, Line 1
String or binary data would be truncated.
The statement has been terminated.

Anu suggestions?
 
bborissov,

I am actually copying data from one table to another, except the data is generic in one table and in a specific format in the second table.

The datatypes are set as char(11) for both tables.
 
OOOPS,
George, that wasn't for you!!!!!
:-)

But I stand on my opinion: Formatting the data is the FrontEnd Job :-)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
I think I discovered the problem. One entry has the maximum number of characters already and cannot add the '-'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top