| Author |
Topic |
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-05-19 : 07:03:37
|
| I cannot see why this does not work?@Item_No = left(@Item_No, len(@Item_No)-2)so if @Item_No = anytext%'I would get anytext as the result, but all I get is incorrect parameter passed to substring function? |
|
|
raclede
Posting Yak Master
180 Posts |
Posted - 2005-05-19 : 07:07:33
|
| forgot to include keyword SET or SELECTset @Item_No = left(@Item_No, len(@Item_No)-2)select @Item_Noselect @Item_No = left(@Item_No, len(@Item_No)-2)select @Item_NoCursors are for those who doesn't know how to use SQL raclede™ |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-05-19 : 07:43:01
|
| Sorry, typo on my part. In my code I do have set as you have it. Still get the error? |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-05-19 : 07:45:07
|
| The exact error is 'invalid length parameter passed to substring function' |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-05-19 : 07:57:28
|
len of emty column is 0 so by subtracting 2 you get -2 which is invalid.Go with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-19 : 08:13:22
|
| yes, as spirit1 said, you need to check thisif len(@Item_No)>=2Beginselect @Item_No = left(@Item_No, len(@Item_No)-2)select @Item_NoendMadhivananFailing to plan is Planning to fail |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-05-19 : 09:58:25
|
| Mmm it works so I can't grumble there, but am a bit confused as doesn't the line above assign a value to @item_no? |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-05-19 : 09:59:47
|
| Can you also explain why you use select and not set and then select again after the assignment please... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-05-19 : 10:15:54
|
| select @Item_No = left(@Item_No, len(@Item_No)-2) is same as that of setIt will assign the value and you have to select it again MadhivananFailing to plan is Planning to fail |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-05-19 : 10:24:08
|
| Gotcha.I modified it to this;if len(@Item_No)>=2select @Item_No = left(@Item_No, len(@Item_No)-2)as I have other code after it. as it was it stop everything else running, but now it works a treat. Thanks |
 |
|
|
|