Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL2008VB.NET
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:30
Edited 4 Jan '13 - 1:52

Comments
URVISHSUTHAR - 3 Jan '13 - 8:13
Hay Harsha, May I know what error you getting :)
Harsha Dev - 3 Jan '13 - 8:21
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.
 
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 - 3 Jan '13 - 22:47
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 - 4 Jan '13 - 0:41
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:26
Thanks for trying... :) No Same Error is poping Out near Update Statement, @Uom_NoOfDecimal expecting an Integer :( Any more Suggesstions are Welcomed.
URVISHSUTHAR - 4 Jan '13 - 7:35
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:42
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 - 4 Jan '13 - 7:43
ya u are write i tried directly casting in select statement but it is not good :)
URVISHSUTHAR - 4 Jan '13 - 7:54
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 414
1 Arun Vasu 253
2 OriginalGriff 190
3 CPallini 163
4 Aarti Meswania 158
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid