SQL - Filtered on QTY field only in a View

Posted on 2012-03-28
Last Modified: 2012-03-28
New to using SQL - I created a view and need to add a field for the Quantity Field, I need this field to exclude one product line in my table.  However, I need the Product Line on the entire table but just filtered for the quantity field. Is there a way to do this?  

For example - My QTY field includes Freight.  My $$ fields need to include the Freight $$'s so I can't eliminate the Freight from the entire table I just don't want the QTY field to include the Freight numbers, as it doubles the Qty Amount.  

In Crystal - I would create a formula as:

If {ProductLine} = "FRGT" then 0 else {Qty}

Any help would be great!  Trying to not do this report in Crystal.  

Thank you.

Using MS SQL Management Studio - 2008 R2 - Free version
Question by:eleale
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
  • 4
  • 2
LVL 13

Expert Comment

ID: 37777831

Can you post your data model?



Author Comment

ID: 37777869

Is this what you need?  See attached.

LVL 101

Expert Comment

ID: 37777917
SOmething like

Case ProductLine
      "FRGT"  :  Cost
      Others  :  Cost * Qty
End  As ExtendedCost

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.


Author Comment

ID: 37777928
Hi Mlmcc:

Where in SQL do you excute a Case Statement? Is it part of the SQL statement?

LVL 101

Accepted Solution

mlmcc earned 500 total points
ID: 37777942
It is part of the SELECT

SELECT fields, CASE .... , fields
FROM ....

I don't have a SQL database here so the syntax is from memory.


Author Comment

ID: 37777947
I will give it a try - Thank you.

Author Closing Comment

ID: 37778469
Thank you!

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

734 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