| Author |
Topic |
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-25 : 12:36:14
|
| Hi All,I need your help on urgent basis pls..i m executing sql query but i am getting errorlikeMsg 8114, Level 16, State 5, Line 20Error converting data type varchar to numeric.my syntax is declare @SecMaxCodeID numeric (3,0)declare @AccountID numeric (3,0)set @AccountID = 187set @SecMaxCodeID = 0set @SecMaxCodeID = convert(decimal, convert (varchar(10), @AccountID) + convert(varchar(25), max(convert(decimal, substring(convert(varchar(50), @SecMaxCodeID),4,datalength(convert(varchar(50),@SecMaxCodeID))))) + 1))select @SecMaxCodeIDT.I.A |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-25 : 12:56:32
|
| Given these inputs:set @AccountID = 187set @SecMaxCodeID = 0What should the result be?Be One with the OptimizerTG |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-25 : 12:59:09
|
| I am getting error for 0 as input for @SecMaxCodeID but for rest of values I m getting no errT.I.A |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-25 : 13:04:21
|
| I'm just trying to see what you expect from this expression. What is the expected result (for any inputs?)Be One with the OptimizerTG |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-25 : 13:07:47
|
| its 1871 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-25 : 13:15:22
|
quote: Originally posted by under2811 its 1871
what's the logic that you're trying to apply? |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-25 : 13:17:24
|
Are you just trying to add 1 to the two concatenated values?select convert(int, convert(varchar(3), @AccountID) + convert(varchar(3), @SecMaxCodeID) ) + 1 Be One with the OptimizerTG |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-25 : 13:19:08
|
| if it is SecMaxCodeID = 1871 then by this it sud give SecMaxCodeID = 1872...like that but in some cases i m getting SecMaxCodeID null so i set it as isnull(SecMaxCodeID ,0)that time i getting this errorT.I.A |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-25 : 13:25:19
|
| select convert(int, convert(varchar(50), @AccountID) + convert(varchar(50), @SecMaxCodeID) ) + 1i tried for AccountID = 187and SecMaxCodeID = 187254I am getting err like Msg 8115, Level 16, State 8, Line 13Arithmetic overflow error converting int to data type numeric. |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-25 : 13:27:20
|
| for value of SecMaxCodeID other than 0 (zero) no problem for me it works fine but when it comes to 0 then i m getting that errT.I.A |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-25 : 13:56:59
|
| The overflow is because you have your variables declared as numeric(3,0)Be One with the OptimizerTG |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-09-25 : 14:00:58
|
| [code]declare @SecMaxCodeID numeric (18,0)declare @AccountID numeric (18,0)set @AccountID = 187set @SecMaxCodeID = 187254select convert(int, convert(varchar(50), @AccountID) + convert(varchar(50), coalesce(@SecMaxCodeID, 0)) ) + 1--output: 187187255set @AccountID = 187set @SecMaxCodeID = null--output: 1871[/code]Be One with the OptimizerTG |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2008-09-26 : 02:52:37
|
| Thanks!!!!! |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-09-26 : 02:57:01
|
What are the rules when @sexmaxcodeid equals 999?set @AccountID = 187set @SecMaxCodeID = 999should the result be "1871000" ? E 12°55'05.63"N 56°04'39.26" |
 |
|
|
|