Solved

TSQL Syntax

Posted on 2012-03-14
2
282 Views
Last Modified: 2012-03-14
I need to delete row in table A (Price Code File, OEPRCFIL)when there is not a match in Table B (Item Master file, IMItmIdx). The field in OEPrcFil that contains the item number is Filler_0001. If Filler_0001 ONLY contained the item number, the TSL would be:

(I will first build a Select rather than a Delete and verify the records)

Select Filler_0001 From OEPrcFil
WHere Filler_0001 Not in (Select Item_No from IMItmIdx)

The above works with the provision that Filler_0001 contains only the Item number. The problem I have is that the Filler_0001 contains data in addition to the Item Number. Specifically, Filler_0001 contains the Vendor Number with the Item Number concatonated onto the end, e.g.  VENDORNOITEMNO = ACMEPRODUCTA or GIANTPRODUCTA.

As you can see the Vendor Number that prepends the Item Number is not a fixed length. Since it is not a fixed length, that preludes identifying the Item Number with Substring.

I need some sort of pattern matching. I have looked at CHARINDEX and PATINDEX but I was not successful in using a SELECT inside those functions.

I am using SQL 2000.

What TSQL syntax would I use to select all the OEPrdFil Records that do not have an item number match in the Item Master table?

Thanks,
pat
0
Comment
Question by:mpdillon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 37720587
This is not 100% logically correct, but perhaps it will steer you in a different direction.

Select Filler_0001 From OEPrcFil o, IMItmIdx m
where m.item_no as varchar(10) =   right(o.filler_0001,len(m.item_no)


What is the datatype of item_no?
do you also have a vendor table that would help construct the vendorproduct key.
0
 

Author Closing Comment

by:mpdillon
ID: 37720876
dqmq,

Great. With some modifications plus information I didn't share (didn't want to confuse you), I was able to solve the problem.

Yes, there is a Customer Master table. It was the "From OEPrcFil o, IMItmIdx M" that I was not familiar with.

Here is my solution

Select * from OEPrcFil_SQL
Where Cd_Tp = 1
and Ltrim(Rtrim(Filler_0001))
not in (Select ltrim(Rtrim(C.Cus_No))+ltrim(Rtrim(I.Item_No))
From IMItmIDX_SQL I, ARCusFil_SQL C)

The Delete query looks like:

Delete from OEPrcFil_SQL
Where Cd_Tp = 1
and Ltrim(Rtrim(Filler_0001))
not in (Select ltrim(Rtrim(C.Cus_No))+ltrim(Rtrim(I.Item_No))
From IMItmIDX_SQL I, ARCusFil_SQL C)


The SELECT is very slow (execution time > 1min) but I only have to do this twice so we will just live with it.

Thank you for your assistance.
pat
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question