Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using parameters in math equations

Author  Topic 

alecd
Starting Member

7 Posts

Posted - 2011-03-09 : 01:41:36
hello,

I'm trying to use a parameter in a math equation, but it doesn't seem to be working.

SET Price = Price * @Percentage

@Percentage is a decimal parameter passed to the sql statement.

Why is this not working?

Thanks,

Alec

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-09 : 01:44:08
what is Price ? is it a column in your table ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-03-09 : 01:44:47
Is that the full query? You can't reference the Price column without referencing the table in the query.

Show us the full query and the error.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

alecd
Starting Member

7 Posts

Posted - 2011-03-09 : 01:50:20
Procedure UpdateCart
(
@Percentage as decimal,
@CartId as int
)
As

UPDATE _Cart
SET Price = Price * @Percentage
WHERE CartId = @CartId
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-09 : 01:52:54
you didn't define any precision & scale for the @percentage decimal data type it will be default to integer

so if you pass in @percentage as 1.25, it will be treated as 1. That's why it is not working.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

alecd
Starting Member

7 Posts

Posted - 2011-03-09 : 02:03:18
still not working. I defined the decimal as: @Percentage decimal (8, 2)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-09 : 02:15:29
please explain exactly what is not working ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

alecd
Starting Member

7 Posts

Posted - 2011-03-09 : 02:15:56
Never mind..... My sql execute definition was wrong..... Thanks khtan!
Go to Top of Page
   

- Advertisement -