Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
declare cursor_deci cursor
 
for select SOuD_CuBal,uom_noofdecimal,sm_code from #itm
declare @sm_code int,@UoM_NoofDecimal int 
declare @SOuD_CuBal as numeric(21,6)
declare @newSOuD_CuBal as numeric(21,6)
open cursor_deci
fetch next from cursor_deci into @SOuD_CuBal,@Uom_Noofdecimal,@sm_code
while (@@FETCH_STATUS =0)
begin
''update #tmp2 SET cubal  = CAST((@SOuD_CuBal)  as decimal(18,@Uom_Noofdecimal)
where sm_code = @sm_code
fetch next from cursor_deci into @SOuD_CuBal,@Uom_Noofdecimal,@sm_code
end
close cursor_deci
deallocate cursor_deci
its giving error near update statement
any suggestions are welcome
 
Thanks and Regards
Harsha
Posted 3-Jan-13 1:30am
Edited 4-Jan-13 1:52am
v4
Comments
URVISHSUTHAR at 3-Jan-13 8:13am
   
Hay Harsha, May I know what error you getting :)
Harsha Dev at 3-Jan-13 8:21am
   
Expecting Integer at @Uom_Noofdecimal :(
 
But i need to pass integer value by parameter. (Through @Uom_noofdecimal)

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hay Harsha,
 
See below code and if you can make your query proper then you can get result as int.
 
declare @aa as decimal(18,2) =25000.545
select cast(@aa as int)
 
Let me know if you have any query for above Smile | :)
  Permalink  
Comments
Harsha Dev at 3-Jan-13 22:47pm
   
ya it will work Thanks, but in the place of int value 2 i need to pass a parameter so that it will take int value from the parameter passed :)
URVISHSUTHAR at 4-Jan-13 0:41am
   
try this :)
 
declare cursor_deci cursor

for select SOuD_CuBal,cast(uom_noofdecimal as int) as uom_noofdecimal,sm_code from #itm
declare @sm_code int,@UoM_NoofDecimal int
declare @SOuD_CuBal as numeric(21,6)
declare @newSOuD_CuBal as numeric(21,6)
open cursor_deci
fetch next from cursor_deci into @SOuD_CuBal,@Uom_Noofdecimal,@sm_code
while (@@FETCH_STATUS =0)
begin
''update #tmp2 SET cubal = CAST((@SOuD_CuBal) as decimal(18,@Uom_Noofdecimal)
where sm_code = @sm_code
fetch next from cursor_deci into @SOuD_CuBal,@Uom_Noofdecimal,@sm_code
end
close cursor_deci
deallocate cursor_deci
Harsha Dev at 4-Jan-13 7:26am
   
Thanks for trying... :)
 
No Same Error is poping Out near Update Statement,
@Uom_NoOfDecimal expecting an Integer :(
 
Any more Suggesstions are Welcomed.
URVISHSUTHAR at 4-Jan-13 7:35am
   
really unable to understand why you need to cast it, you can define decimal directly
 
there is something you must need to think, what you say? :)
Harsha Dev at 4-Jan-13 7:42am
   
directly if i put integer then its hard Coded no use, I have a UnitMaster table in the database where i have column named UoM_NooFDecimal it is an integer value. through that unitmaster table and UoM_noOfDecimal column i am trying to cast the column Cubalto no of decimal places.
Harsha Dev at 4-Jan-13 7:43am
   
ya u are write i tried directly casting in select statement but it is not good :)
URVISHSUTHAR at 4-Jan-13 7:54am
   
May I know why it is not? :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 310
1 CPallini 310
2 George Jonsson 269
3 Gihan Liyanage 255
4 OriginalGriff 245
0 OriginalGriff 4,903
1 CPallini 3,960
2 Sergey Alexandrovich Kryukov 3,474
3 George Jonsson 2,786
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140905.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100