sql server - SQL Insert in Temp table WHERE clause isn't working properly -
i have qestion. have script take records table, rid of duplicates , add together quantity field. needs done if charid = 0, @ moment grabbing item records , combining duplicate records. here script. can see statement after select statement. doing wrong? using navicat
declare @tempsum table ( customerid int, itemid int, var1 int, inventoryid int, quantity int) -- sum of quantity per customer, item , var1 -- first invetoryid, assuming smallest number first 1 insert @tempsum ( customerid, itemid, var1, inventoryid, quantity ) select customerid, itemid, var1, min(inventoryid), sum(quantity) usersinventory charid = 0 -- isn't working?? grouping customerid, itemid, var1 begin transaction -- remove duplicate items delete usi usersinventory usi bring together @tempsum tmp on tmp.customerid = usi.customerid , tmp.itemid = usi.itemid , tmp.var1 = usi.var1 , tmp.inventoryid <> usi.inventoryid -- ensures items deleted didn't mark our firsts -- update quantity summed before update usi set quantity = tmp.quantity usersinventory usi bring together @tempsum tmp on tmp.customerid = usi.customerid , tmp.itemid = usi.itemid , tmp.var1 = usi.var1 , tmp.inventoryid = usi.inventoryid commit transaction
here struct
inventoryid bigint customerid int charid int backpackslot int itemid int leaseduntil datetime quantity int var1 int var2 int durability int
sql sql-server database tsql insert
No comments:
Post a Comment