Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Keep up the very good job that you and your team are doing. This site has replaced my morning cup of tea as a must have/do!!!..."

Geography

Where in the world do Tek-Tips members come from?
up4a (TechnicalUser)
25 Apr 12 19:32
I have an access program used to create a .csv file used to upload invoicing to a customer (like EDI but not standard, the Purchase Order's (PO) are not sent electronically)

The problem that I have encountered is that there are items called "KIT" items that the customer orders as a single part number but the ERP system adds lines in the sales order for the components of the 'parent' item.  The .csv file needs to reference the original PO line number.

I would like to re_number the sales order lines in a query eliminating the components for the order.

So the tbl_sales has records

SO_no Line_no Comp_Item
12345  1         N
12345  2         N
12345  3         Y
12345  4         Y
12345  5         N

Hopefully the Query would return


SO_no Line_no Comp_Item PO_Line
12345  1         N        1
12345  2         N        2
12345  5         N        3

I need to keep the Original Sales order Line to then link it to the Invoice.

Any suggestions would be great!

Our back up plan is to add a field at order entry to record the PO line but since this is only used for some of the customers that would be extra (useless) work for the order entry process.

Thanks so much!  
PHV (MIS)
25 Apr 12 20:57
What about this ?

CODE

SELECT A.SO_no, A.Line_no, A.Comp_Item
, (SELECT Count(*) FROM tbl_sales WHERE SO_no=A.SO_no AND Line_no<=A.Line_no AND Comp_Item='N') AS PO_Line
FROM tbl_sales AS A
WHERE A.Comp_Item='N'
GROUP BY A.SO_no, A.Line_no, A.Comp_Item

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

up4a (TechnicalUser)
27 Apr 12 13:24
I am not very skilled in code so the 'A.'  is confusing me.  The below is what I tried in the SQL Query editor (I simplified my original table/fields but the logic is the same..) when I try to run it, it requests each parameter value.

SELECT A.SO_SalesOrderHistoryDetail.SalesOrderNo, A.SO_SalesOrderHistoryDetail.SequenceNo, A.SO_SalesOrderHistoryDetail.ExplodedKitItem, (SELECT Count(*) FROM SO_SalesOrderHistoryDetail Where SO_SalesOrderHistoryDetail.SalesOrderNo=A.SO_SalesOrderHistoryDetail.SalesOrderNo AND SO_SalesOrderHistoryDetail.SequenceNo=A.SO_SalesOrderHistoryDetail.SequenceNo AND SO_SalesOrderHistoryDetail.ExplodedKitItem<>"C") AS PO_Line
FROM SO_SalesOrderHistoryDetail AS A
WHERE A.SO_SalesOrderHistoryDetail.ExplodedKitItem<>"C"
GROUP BY A.SO_SalesOrderHistoryDetail.SalesOrderNo, A.SO_SalesOrderHistoryDetail.SequenceNo, A.SO_SalesOrderHistoryDetail.ExplodedKitItem

I apologize for my lack of skills, this forum has been so helpful in the past and this is the 1st time I have actually had to post a ??

 
PHV (MIS)
27 Apr 12 13:30
I"d try this:

CODE

SELECT A.SalesOrderNo, A.SequenceNo, A.ExplodedKitItem
, (SELECT Count(*) FROM SO_SalesOrderHistoryDetail Where SalesOrderNo=A.SalesOrderNo AND SequenceNo=A.SequenceNo AND ExplodedKitItem<>"C") AS PO_Line
FROM SO_SalesOrderHistoryDetail AS A
WHERE A.ExplodedKitItem<>"C"

Hope This Helps, PH.
FAQ219-2884: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

Andrzejek (Programmer)
27 Apr 12 13:53
   
"the 'A.' is confusing me"

You simply susbsitute your SO_SalesOrderHistoryDetail with the letter A in your Select statement in "FROM SO_SalesOrderHistoryDetail AS A".  It is an allias.

You may as well say:
FROM SO_SalesOrderHistoryDetail AS XYZ
and wherever you have the name of SO_SalesOrderHistoryDetail, you use XYZ instead.

Have fun.

---- Andy

up4a (TechnicalUser)
27 Apr 12 14:55
The Query runs but it returns 1 for every PO_Line, it doesn't "re-number" (Thanks again for the help!)
up4a (TechnicalUser)
27 Apr 12 18:01
I got this to work but it is really slow..

SELECT A.SalesOrderNo, A.SequenceNo, A.SkipPrintCompLine
, (SELECT Count(*) FROM SO_SalesOrderHistoryDetail B Where A.SalesOrderNo=B.SalesOrderNo AND A.SequenceNo>=B.SequenceNo AND A.SkipPrintCompLine<>"Y") AS PO_Line
FROM SO_SalesOrderHistoryDetail AS A
WHERE A.SkipPrintCompLine<>"Y" AND A.SalesOrderNo Is Not Null
ORDER BY A.SalesOrderNo, A.SequenceNo

Maybe I can make a table from this sub-query and then only append it going forward to save some time.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close