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 2005 Forums
 Transact-SQL (2005)
 Question: How to format a column

Author  Topic 

JDrown
Starting Member

10 Posts

Posted - 2007-10-17 : 10:54:00
I need to format a numeric column (all have 7 digits) to rendered in an SQK statements as "00-00-0000". Assume the name of the table and column name are Part and Part Description. How would I write it correctly in Transact-SQL? I've come from Access, and the differences between the two stagger me.

Please help if possible.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-17 : 10:58:03
SELECT STUFF(STUFF(Col1, 5, 0, '-'), 3, 0, '-')
FROM Table1

SELECT LEFT(Col1, 2) + '-' + SUBSTRING(Col1, 3, 2) + '-' + RIGHT(Col1, 4)
FROM Table1



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-10-17 : 11:46:25
quote:
Originally posted by JDrown
I've come from Access, and the differences between the two stagger me.

Please help if possible.



Is Access a bar?

You shouldn't drink before Noon



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-10-17 : 16:24:34
quote:
Originally posted by X002548


You shouldn't drink before Noon

Brett

8-)



Wrong! ;)
Go to Top of Page
   

- Advertisement -