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 2008 Forums
 Transact-SQL (2008)
 replacement for substring

Author  Topic 

causative
Starting Member

2 Posts

Posted - 2013-11-13 : 11:23:29
Hello
My postcode format in my database is: 20470 and I use the following query to transform it to format: 20-470

((substring((STR(postcode)),6,2)+'-'+substring((STR(postcode)),8,3)))

Is it possible to do in another way?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-11-13 : 11:33:44
one way:
stuff(postcode, 3, 0, '-')

Be One with the Optimizer
TG
Go to Top of Page

causative
Starting Member

2 Posts

Posted - 2013-11-13 : 11:44:33
that is the point
thx a lot
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-11-13 : 13:56:40
you're welcome. You should use books online often - it is very helpful for exploring things like this. For example here are string functions.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -