Solved

building a string in a query

Posted on 2013-06-08
2
271 Views
Last Modified: 2013-06-09
I am trying to build a string in q query I will use for a column Description. How would I properly use case belw?

SELECT     11 AS Expr1, od.DeliveryDateRequest, od.GrowthStageID, od.Quantity, od.ProductID, od.UnitPrice, od.TotalPrice, od.SpecialDiscount, 
                      gs.GrowthStageName, p.Productname, 
p.Productname + ' - ' + gs.GrowthStageName  
case when od.SpecialDiscount <> 0 then + od.SpecialDiscount + ' Discount' end  AS Comments
FROM         WW.ClientOrderDetails AS od INNER JOIN
                      WW.Products AS p ON od.ProductID = p.ProductID INNER JOIN
                      WW.GrowthStage AS gs ON od.GrowthStageID = gs.GrowthStageID
WHERE     (od.OrderID = 401025)

Open in new window

0
Comment
Question by:Shawn
[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 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 39232422
SELECT
	11 AS Expr1
	, od.DeliveryDateRequest
	, od.GrowthStageID
	, od.Quantity
	, od.ProductID
	, od.UnitPrice
	, od.TotalPrice
	, od.SpecialDiscount
	, gs.GrowthStageName
	, p.Productname
	, p.Productname + ' - ' + gs.GrowthStageName + 
	case when od.SpecialDiscount <> 0 then CAST(od.SpecialDiscount as varchar) + ' Discount' else '' end AS Comments
FROM         WW.ClientOrderDetails AS od INNER JOIN
                      WW.Products AS p ON od.ProductID = p.ProductID INNER JOIN
                      WW.GrowthStage AS gs ON od.GrowthStageID = gs.GrowthStageID
WHERE     (od.OrderID = 401025)

Open in new window

0
 
LVL 1

Author Closing Comment

by:Shawn
ID: 39233193
thank you
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

756 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