Click here to Skip to main content
14,698,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Hope someone can help me with this, I want to
add certain amount(Depending on parameter) add it
to the amount in my table.

What type of procedure would I use for something like this?

This is what i have tried:
create proc usp_CancelSale
@Name nvarchar(50),
@Quantity nvarchar (50)
as
update tblSales 
set
Product = @Name,
Amount  = COUNT(@Quantity)
where Product = @Name


PLEASE ANY HELP WOULD BE APPRICIATED.
Posted
Updated 7-Sep-11 12:29pm
v2
Comments
Ben Paxton 7-Sep-11 17:27pm
   
This is what i have tried:

create proc usp_CancelSale
@Name nvarchar(50),
@Quantity nvarchar (50)
as
update tblSales
set
Product = @Name,
Amount = COUNT(@Quantity)
where Product = @Name
Wendelius 7-Sep-11 17:27pm
   
Could you give a small example? Nevermind, you posted it the same moment I asked.
Ben Paxton 7-Sep-11 17:29pm
   
Parameter @Quantity must add into the "Amount" column of the table
Elina Blank 7-Sep-11 17:37pm
   
@Quantity is a varchar. What are you trying to do?
so, count(varchar) will return 1 (1 row)

1 solution

If I understood correctly, if quantity is going to be added to the amount then you could use something like:
update tblSales
set
Product = @Name,
Amount  = Amount + @Quantity
where Product = @Name

Also the @Quantity is now defined as nvarchar (50) in the parameters. If it's a number you should use proper datatype for the parameter (decimal, int, ...)
   
Comments
Ben Paxton 7-Sep-11 17:35pm
   
Thanks alot!!
Wendelius 7-Sep-11 17:36pm
   
You're welcome :)

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