Solved

SQL Query

Posted on 2013-01-09
3
285 Views
Last Modified: 2013-01-09
Hello,

I am in need of some assistance. I have an SQL DB that I need to run this query - however I do not know how to write the query beyond what is below.

SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku]

Basically, I need to look at each InvoiceNumber and check to see if it contains any item [QtySold] => 12. If true than display all InvoiceNumbers that do not contain [Sku] = "QUIK".

Let me know if this is unclear or if you require further information.

Thank you very much for any assistance you can offer.

Ryan
0
Comment
Question by:Ryan Rood
  • 2
3 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 38759413
try

SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku] a
  where exists(select 1 from [Sku] b where a.InvoiceNumber = b.InvoiceNumber and QtySold >= 12)
      and a.SKU <> 'QUIK'
0
 
LVL 9

Expert Comment

by:sognoct
ID: 38759415
SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku]
 WHERE QtySold >= 12 AND NOT InvoiceNumber LIKE '%QUIK%'

Open in new window

0
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 38759426
oops

SELECT [OrderNumber]
      ,[Date]
      ,[Branch]
      ,[InvoiceNumber]
      ,[Sku]
      ,[AccountNumber]
      ,[QtySold]
  FROM [SRIRRA50ED8483SQL].[dbo].[Sku] a
  where exists(select 1 from [SRIRRA50ED8483SQL].[dbo].[Sku] b where a.InvoiceNumber = b.InvoiceNumber and QtySold >= 12)
      and not exists(select 1 from [SRIRRA50ED8483SQL].[dbo].[Sku] b where a.InvoiceNumber = b.InvoiceNumber and b.SKU = 'QUIK')
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now