web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Help with sql query

(0) ShareShare
ReportReport
Posted on by 2,395

Hi all I have a query wich I use for labels for our finished product, it takes all lines from a sales order and print 1 label for each product with a serial number, but when there are different products it prints all serials for each product, heres an example so I can make my self more clear.

Sales order:

Item       serials
--------------------------------
item1     serial1, serial2
item2     serial3, serial4
item3     serial5

what this query should print are 5 labels:
item1 - serial1
item1 - serial2
item2 - serial3
item2 - serial4
item3 - serial5

But what my query prints is:
item1 - serial1
item1 - serial2
item1 - serial3
item1 - serial4
item1 - serial5
item2 - serial1
item2 - serial2
item2 - serial3
item2 - serial4
item2 - serial5
item3 - serial1
item3 - serial2
item3 - serial3
item3 - serial4
item3 - serial5

so if any one could take a look at my query and tell me where i'm wrong, here's the query:

SELECT     dbo.SOP10100.SOPNUMBE, dbo.SOP10201.SERLTNUM, dbo.SOP10100.CUSTNAME, dbo.SOP10200.ITEMNMBR, dbo.IV00101.ITMSHNAM
FROM         dbo.SOP10100 INNER JOIN
                      dbo.SOP10200 ON dbo.SOP10100.SOPNUMBE = dbo.SOP10200.SOPNUMBE INNER JOIN
                      dbo.SOP10201 ON dbo.SOP10100.SOPNUMBE = dbo.SOP10201.SOPNUMBE INNER JOIN
                      dbo.IV00101 ON dbo.SOP10200.ITEMNMBR = dbo.IV00101.ITEMNMBR

Thanks in advance.

Regards

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Victoria Yudin Profile Picture
    22,769 on at

    Try this:

    SELECT s.SOPNUMBE, s.SERLTNUM, h.CUSTNAME, d.ITEMNMBR, i.ITMSHNAM

    FROM    SOP10201 s

    INNER JOIN SOP10100 h

    ON s.SOPNUMBE = h.SOPNUMBE and s.SOPTYPE = h.SOPTYPE                      

    INNER JOIN SOP10200 d

    ON s.SOPNUMBE = d.SOPNUMBE and s.SOPTYPE = d.SOPTYPE and s.LNITMSEQ = d.LNITMSEQ and s.CMPNTSEQ = d.CMPNTSEQ  

    INNER JOIN IV00101 i

    ON d.ITEMNMBR = i.ITEMNMBR

  • Alvaro Rodríguez Ochoa Profile Picture
    2,395 on at

    Wow Victoria, this did it, thanks a lot, also thanks on a great site.

  • Victoria Yudin Profile Picture
    22,769 on at

    Alvaro,

    You are very welcome, thanks for the kind words. :-)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
Dan Liebl Profile Picture

Dan Liebl 2

#2
Shravan Attelli Profile Picture

Shravan Attelli 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans