c# - Update quantity with same column value name -


i have following data in database table (items):

enter image description here

above image shows row 1 , row 2 have same values.

my question how can delete row 2, because detects have same product name, add quantity? example row 2 quantity added row 1 quantity. row 1 quantity have 20 rather 10, , database table have 1 row.

sorry not providing code.

sql insert query above image:

insert [items] ([category], [name], [quantity], [price], [label], [status]) values (@category, @name, @quantity, @price, @label, @status) 

sql select query above image:

select [category], [name], [quantity], [price], [label], [status], [imagedata] [items] [status] = @active order [category] asc; 

the @active parameter active.

t-sql create table:

create table [dbo].[items] (     [id]            int             identity (1, 1) not null,     [category]      nvarchar (50)   null,     [name]          nvarchar (50)   null,     [quantity]      smallint        null,     [price]         decimal (18)    null,     [label]         nvarchar (50)   null,     [status]        nvarchar (50)   null,     [imagedata]     varbinary (max) null,     primary key clustered ([id] asc) ); 

what want do:

i want delete second row database, before that, check first , second row if there same product name, if there is, delete last row (which second row in example), , update quantity in first row quantity in second row. if first row have 10 quantity, , second row have 20 quantity, first row have 30 quantity, , second row gone (deleted)

this sql group you. summing price , grouping rest of columns.

select      [category],      [name],      sum([quantity]),      [price],      [status],      [imagedata]  [items] [status] = @active order [category] asc group          [category],      [name],      [price],      [status],      [imagedata]  

ideally should have "productid" column in table can group instead of relying on procuct name being unique.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -