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)
 How to Substring an Integer Value

Author  Topic 

Looper
Yak Posting Veteran

68 Posts

Posted - 2011-04-08 : 04:01:22
What is the best way to substring an integer value

e.g a value of 2010, I want it to be 10 in my variable?

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-08 : 04:10:48
For example:
select right(str(2010),2)


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-04-08 : 04:11:16
1) SELECT RIGHT(Col1, 2) FROM dbo.Table1
2) SELECT Col2 % 100 FROM dbo.Table1



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-08 : 07:08:42
So simple...
SELECT 2010 - 2000


______________________
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-08 : 07:11:00
quote:
Originally posted by ms65g

So simple...
SELECT 2010 - 2000


______________________




And if there are different values in column instead of this hard coded value 2010 then ? ;). I think PESO answer is perfect

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-08 : 07:13:48
quote:
Originally posted by lionofdezert

quote:
Originally posted by ms65g

So simple...
SELECT 2010 - 2000


______________________




And if there are different values in column instead of this hard coded value 2010 then ? ;). I think PESO answer is perfect

--------------------------
http://connectsql.blogspot.com/


Are you OP?

______________________
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-04-08 : 08:10:52
quote:
Originally posted by ms65g

So simple...
SELECT 2010 - 2000


______________________



If it is simple like that then it is also simple like this:
SELECT 10



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-08 : 08:18:56
quote:
Originally posted by webfred

quote:
Originally posted by ms65g

So simple...
SELECT 2010 - 2000


______________________



If it is simple like that then it is also simple like this:
SELECT 10



No, you're never too old to Yak'n'Roll if you're too young to die.


The problem is very simple so the solution is simple to.
SELECT 10 is constant and static by following query is not joke:
SELECT column - 2000
FROM TableName;


______________________
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-04-08 : 16:47:15
All other, what about value 1998?
I think OP need that to result in 98, not -2.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-09 : 18:06:32
@Peso,
Okay. Please participate in following topic; I have a surprised query for competition.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=159262

______________________
Go to Top of Page
   

- Advertisement -