Solved

building a string in a query

Posted on 2013-06-08
2
259 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
2 Comments
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
Comment Utility
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
Comment Utility
thank you
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

762 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

10 Experts available now in Live!

Get 1:1 Help Now