Solved

building a string in a query

Posted on 2013-06-08
2
262 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

867 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

17 Experts available now in Live!

Get 1:1 Help Now