C# .NET - How to include decimal places in stored procedure?

Asked By Dom Afonso on 13-Jun-12 01:34 AM
I have a stored procedure that I want to include 2 decimal paces in @UnitPrice parameter. Can anyone let me know how to include 2 decimal places?
Below is the stored procedure I use:

ALTER procedure [dbo].[UpdateCalculus]
@UnitPrice decimal
as
begin
update Calculus 
set UnitPrice=@UnitPrice
Where CalculuID=1
end
S K replied to Dom Afonso on 13-Jun-12 01:37 AM
Just use numeric datatype in stored procedure so you will get decimal value
eg

Declare @no numeric(19,2)
set @no =10.5
print @no

Output is 
10.50

even you assign the integer that also contain 00 after decimal place as
Declare @no numeric(19,2)
set @no =10
print @no

Outupt is
10.00
Chintan Vaghela replied to Dom Afonso on 13-Jun-12 02:06 AM

Hi Frndz,

 

Functionality: Added Decimal in SP

 

 

 

Convert parameter value into Decimal

 

convert(decimal(10,2),100, 2)

 

 

 

 

Query:

 

ALTER procedure [dbo].[UpdateCalculus]

@UnitPrice decimal

as

begin

update Calculus

set UnitPrice=convert(decimal(10,2),@UnitPrice, 2)

Where CalculuID=1

 

Hope this helpful!

Thanks

 

 

 

Chintan Vaghela replied to Dom Afonso on 13-Jun-12 02:10 AM

Hi Frndz,

 

Functionality: Added Decimal in SP

 

Second Way

 

 

In sp Parameter declare decimal value as following way

 

@UnitPrice decimal (20,2)

 

 

 

 

Query:

 

ALTER procedure [dbo].[UpdateCalculus]

    @UnitPrice decimal (20,2)

as

begin

    update Calculus

    set UnitPrice=@UnitPrice

    Where CalculuID=1

end

Hope this helpful!

Thanks