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
 General SQL Server Forums
 New to SQL Server Programming
 SUBSTRING

Author  Topic 

tariq2
Posting Yak Master

125 Posts

Posted - 2012-05-10 : 10:52:10
Hi.

I would like to extract the first 10 digits of each of the following, so that i get:
1201531201, 1201531202 etc.etc.

I can obviously use SUBSTRING('1201531201 - PFJ 2012',1,10)
for each row, but is there someyhing more efficient? Thank you

1201531201 - PFJ 2012
1201531202 - PFJ 2012
1201531203 - PFJ 2012
1201531204 - PFJ 2012
1201531205 - PFJ 2012
1201531206 - PFJ 2012
1201531207 - PFJ 2012
1201531208 - PFJ 2012
1201531209 - PFJ 2012
1201531210 - PFJ 2012
1201531211 - PFJ 2012
1201531212 - PFJ 2012
1201531213 - PFJ 2012
1201531214 - PFJ 2012
1201531215 - PFJ 2012
1201531216 - PFJ 2012
1201531217 - PFJ 2012
1201531218 - PFJ 2012
1201531219 - PFJ 2012
1201531220 - PFJ 2012
1201531221 - PFJ 2012
1201531222 - PFJ 2012
1201531223 - PFJ 2012
1201531224 - PFJ 2012
1201531225 - PFJ 2012

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-10 : 10:58:35
nope. It is can be a little shorter if you use LEFT(<column> , 10) that all. It is not really more efficient that what you have


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-10 : 11:59:11
will it always be 10 digits you want or are you looking at always first part ie part before -?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -