Lets say I have an integer value 2002012, I want to convert it to a string so I can cut the value 4 spaces so that it reads 2002 and then convert it back to an int to add one to it. The name of the field is PERIOD.
CONVERT(Int, SUBSTRING(CAST(PERIOD As Varchar),1,4)) + 1
Is that possible at all or will I get an error?
Is that possible at all or will I get an error?
Give a try, then. It's easy, isn't it?
|||This is also possible
declare @.i int
select @.i = 2002012
select left(@.i,4) +1
they will both work see below
declare @.i int
select @.i = 2002012
select left(@.i,4) +1,CONVERT(Int, SUBSTRING(CAST(@.i As Varchar),1,4)) + 1
Denis the SQL Menace
http://sqlservercode.blogspot.com/
No comments:
Post a Comment