Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Query returns 2 rows, TOP 1 returns none...why?

$
0
0

Hi everyone,

i am bashing my head against a wall here. I cannot explain why this is happening and i hope someone can explain to me what it is.

If i use this code.

---------------------

SELECT [MainJobDetails].[JobNo] mjdjn, [il].[JobNo] iljn, [il].[InvoiceNo],[il].[IsCreditNote], [MainJobDetails].Ref1, JobDesc, [il].NettAmount, [il].[Datedb]
FROM [thardata].[dbo].[MainJobDetails]
CROSS APPLY
(
SELECT InvoiceLines.JobNo, InvoiceLines.Datedb, InvoiceLines.InvoiceNo, InvoiceLines.IsCreditNote, InvoiceLines.NettAmount
FROM InvoiceLines
WHERE InvoiceLines.JobNo = MainJobDetails.JobNo
) il
inner join [Customers] on [Customers].[Code] = [MainJobDetails].[InvoiceCustomerCode] where [Customers].[Department] is null and [MainJobDetails].Ref1 like '%' and [MainJobDetails].[InvoiceCustomerName] NOT LIKE 'MyData%' and [il].[Datedb]...


Viewing all articles
Browse latest Browse all 4871

Trending Articles