Question : sybase sql

experts -
I asked this question before and got an excellent answer:
http://www.experts-exchange.com/Database/Sybase/Q_22690230.html

working like a charm.

But have another issue which I didnt think of that at that time.
what if there is already a row with PNXXXX in the table -- then it will have a duplicate row.

Basically it should leave that row untouched
so this is what needs to be done

Table (ABC) has 5 cols
block_acc
sub_acc
prod_type
trade_type
country

the table has to update all the rows where block_acc or sub_acc like 'V1%' to 'PNXXXX'
but don't touch the rows that are already there with PNXXXX, and I have to prepare a report also something like:

V1XXXX moved to PNXXXXX
V1XXXX not touched because PNXXXX already exist.

earlier I thought solution will work as below:

UPDATE ABC
      SET block_acc = STUFF(block_acc,1,2,'PN')
 WHERE block_acc LIKE 'V1%'

and

UPDATE ABC
      SET sub_acc = STUFF(sub_acc,1,2,'PN')
 WHERE sub_acc LIKE 'V1%'

but I missed the point if PN rows are already there.

So I guess below should be done:
1). select into temp all the rows which starts with V1
2). Join ABC table with temp table and somehow get only the rows which are not there.

well, not sure how to do this and to have data for reporting purpose also ..
please help!

Answer : sybase sql

First, SELECT/INTO BULK COPY should NEVER, NEVER be disabled on the TEMPDB.  It is enabled by default and no one (including the DBA) should ever disable it on TEMPDB.  This may be having a bad effect on performance for queries that create work tables under the covers.  In any case, there is no danger of corrupting the tempdb in the event of a mid-transaction system crash since tempdb is recreated each time the database is started.

It may well be disabled on your user database (which will not prevent select/into a #table operation).  Since you are doing replication, presumably with Sybase RepServer, the DBA may have felt that this would prevent any unlogged operations that could screw up the replication scheme.

Bottom line, if your DBA has disabled this in TEMPDB, get him to change it, or have him contact me and I will 'splain it to him/her.

Now, about your syntax question.....

The word JOIN is part of the ANSI SQL standard Join syntax and is documented in the Sybase manuals.  (You have downloaded the PDFs to your PC for quick reference, right?).

The Join syntax is functionally equivalent to the FROM tab1, tab2, ... WHERE sarg, sarg, sarg... syntax EXCEPT when you are doing Left or Right Outer joins.  Outer joins are less ambiguously expressed using the ANSI syntax.

The reason I used the ANSI syntax here is that is often easier to read and the intent (Join sargs versus filter sargs) is clearer to the reader.  I have slowly converted to the ANSI syntax for everything simply so the next poor schmuck who comes along will have an easier time maintaining it.

Replication will not be broken.  Sybase RepServer reads the log for most things (don't ask about the exceptions) and propagates the changes that way.  

Best of luck,
Bill
Random Solutions  
 
programming4us programming4us