Solved

building a string in a query

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

832 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