Question

When I perform the following SELECT statement:

SELECT startdate
      ,enddate
      ,invoicenumber
      ,vendornumber
      ,upc
      ,store
      ,cost
      ,allowance
      ,reason
      ,row_number() over(partition by upc order by startdate desc) as rownum 
FROM db.table
WHERE  StartDate=DATE'2014-01-01' 
   AND EndDate=DATE'2014-01-01' 
   AND InvoiceNumber IS NULL 
   AND VendorNumber='2505' 
   AND UPC='1234568' 
   AND Store IS NULL 
   AND Cost=1.01 
   AND Allowance IS NULL

I get 2 results: results

How do I update the UPC on the first row only?

Was it helpful?

Solution

You can solve proble in 3 steps

--1) create volatile table with one row you need
create MULTISET  volatile table  t_tc_temp as 
(SELECT startdate ,enddate ,invoicenumber ,vendornumber
      ,upc ,store ,cost ,allowance,reason
 FROM db.table
WHERE  StartDate=DATE'2014-01-01' 
   AND EndDate=DATE'2014-01-01' 
   AND InvoiceNumber IS NULL 
   AND VendorNumber='2505' 
   AND UPC='1234568' 
   AND Store IS NULL 
   AND Cost=1.01 
   AND Allowance IS NULL  
   group by 1,2,3,4,5,6,7,8,9)
   with data NO PRIMARY INDEX ON COMMIT PRESERVE ROWS;
--  2) delete duplicated rows
 delete from db.table where  -- .... yor  conditions

--- 3) insert one row from volatile tabel
    insert into db.table 
    (select t.* from t_tc_temp t 
    -- insert updated row  for example
    union           
     SELECT startdate ,enddate ,invoicenumber ,vendornumber
          ,1111 ,store ,cost ,allowance,reason from t_tc_temp t2 )

P.S. or you can create SET volatile table with Primary Index and withou group by, cause set table checks duplicates

OTHER TIPS

Short answer: you can't (unless your system enabled ROWID, but there's only a very low probability).

But you could insert the rows into a Volatile Table, Delete and re-Insert from the VT.

Btw, is there no Primary Key for this table?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top