Solved

SQL Query

Posted on 2013-01-09
3
288 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

752 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