I'm having some trouble with the below query. The first part runs correctly. see below; I had to change some of the table names etc. since I was posting this
SELECT DISTINCT
derivedtbl_1.MANIFESTNO, derivedtbl_1.INVOICENO, derivedtbl_1.INVOICEDATE, derivedtbl_1.SYSCOST, derivedtbl_1.SYSSELL, derivedtbl_1.DEST,
derivedtbl_1.SEQ, derivedtbl_1.XFROM OPENQUERY(LinkedServer,
'SELECT x.x AS DEST
,x.x AS MANIFESTNO
,x.x AS INVOICENO
,x.x AS INVOICEDATE
,x.x AS SYSCOST
,x.x AS SYSSELL
,x.x AS SEQ
,x.x AS X
FROM Table LEFT OUTER JOIN
x ON x.x = x.x
LEFT OUTER JOIN x ON x.x = x.x
LEFT OUTER JOIN x ON x.x = x.x
WHERE
x.x BETWEEN 20120101 AND 20120131
AND
x.x= ''**''
AND
x.x= ''022''')
AS derivedtbl_1 LEFT OUTER JOIN
DrumSamples ON derivedtbl_1.MANIFESTNO = DrumSamples.MANIFEST
GROUP BY derivedtbl_1.MANIFESTNO, derivedtbl_1.INVOICENO, derivedtbl_1.INVOICEDATE, derivedtbl_1.SYSCOST, derivedtbl_1.SYSSELL, derivedtbl_1.DEST,
derivedtbl_1.SEQ, derivedtbl_1.X
ORDER BY derivedtbl_1.MANIFESTNO
Returns the below data - which is correct
000039111 202213317 20120126 0.07 25.00
000039111 202213317 20120126 15.00 26.60
000039111 202213317 20120126 39.82 59.73
000039111 202213317 20120126 40.00 25.00
Now as soon as I ask for another field called PCODE from the DrumSamples table, it returns 16 records instead of 4. I have tried several different ways to try and stop this but can't seem to get it to work correctly.
See below
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
any help would be appreciated.
Thanks in advance
SELECT DISTINCT
derivedtbl_1.MANIFESTNO, derivedtbl_1.INVOICENO, derivedtbl_1.INVOICEDATE, derivedtbl_1.SYSCOST, derivedtbl_1.SYSSELL, derivedtbl_1.DEST,
derivedtbl_1.SEQ, derivedtbl_1.XFROM OPENQUERY(LinkedServer,
'SELECT x.x AS DEST
,x.x AS MANIFESTNO
,x.x AS INVOICENO
,x.x AS INVOICEDATE
,x.x AS SYSCOST
,x.x AS SYSSELL
,x.x AS SEQ
,x.x AS X
FROM Table LEFT OUTER JOIN
x ON x.x = x.x
LEFT OUTER JOIN x ON x.x = x.x
LEFT OUTER JOIN x ON x.x = x.x
WHERE
x.x BETWEEN 20120101 AND 20120131
AND
x.x= ''**''
AND
x.x= ''022''')
AS derivedtbl_1 LEFT OUTER JOIN
DrumSamples ON derivedtbl_1.MANIFESTNO = DrumSamples.MANIFEST
GROUP BY derivedtbl_1.MANIFESTNO, derivedtbl_1.INVOICENO, derivedtbl_1.INVOICEDATE, derivedtbl_1.SYSCOST, derivedtbl_1.SYSSELL, derivedtbl_1.DEST,
derivedtbl_1.SEQ, derivedtbl_1.X
ORDER BY derivedtbl_1.MANIFESTNO
Returns the below data - which is correct
000039111 202213317 20120126 0.07 25.00
000039111 202213317 20120126 15.00 26.60
000039111 202213317 20120126 39.82 59.73
000039111 202213317 20120126 40.00 25.00
Now as soon as I ask for another field called PCODE from the DrumSamples table, it returns 16 records instead of 4. I have tried several different ways to try and stop this but can't seem to get it to work correctly.
See below
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
000039111 202213317 20120126 0.07 25.00 1234
000039111 202213317 20120126 15.00 26.60 2012
000039111 202213317 20120126 39.82 59.73 4567
000039111 202213317 20120126 40.00 25.00 0001
any help would be appreciated.
Thanks in advance