Click here to Skip to main content
15,881,856 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
SQL
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
Updated 4-Jan-13 1:52am
v4
Comments
URVISH_SUTHAR1 3-Jan-13 8:13am    
Hay Harsha, May I know what error you getting :)
Harsha Dev 3-Jan-13 8:21am    
Expecting Integer at @Uom_Noofdecimal :(

But i need to pass integer value by parameter. (Through @Uom_noofdecimal)

1 solution

Hay Harsha,

See below code and if you can make your query proper then you can get result as int.

SQL
declare @aa as decimal(18,2) =25000.545
select cast(@aa as int)


Let me know if you have any query for above :)
 
Share this answer
 
Comments
Harsha Dev 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 :)
URVISH_SUTHAR1 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 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.
URVISH_SUTHAR1 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 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900