Solved

Return greater of two fields

Posted on 2006-06-21
1
303 Views
Last Modified: 2010-08-05
Hi There,

I am joining two tables, both have a price. I only want to return a single price field which on a record by record basis is the larger of the two.

For example:
Price 1   Price 2    Returned Price
0              7              7
2              5              5
7              1              7
9              0              9
etc.

I Need MSSQL syntax I can use in the view below. Note in the second half of the unity where I'm using a GREATEST() function. Unfortunately MSSQL doesn't have such a function!  Need the equivalent funciton or a work around so I can put something like:

GREATEST(mp.ProductPrice,pp.Price) as ProductPrice

in the SELECT clause . . .

Here's my view:
CREATE VIEW ProjectProductView
 
AS
 
 SELECT ProductID, ProductTitle, ProductName, ProductSKU ,ProductCategoryList, ProductOverview, ProductDescription, ProductMetaKeywords, ProductPrice, ProductSalePrice, ProductPetMedsPrice, ProductMainImage, ProductThumbnailImage, ProductWeight, ProductMinimumPrice, ProductProjectID, ProductID as DistinctID
 FROM CUSTOM_PRODUCT mp
 UNION ALL
 SELECT mp.ProductID, ProductTitle, ProductName, ProductSKU ,ProductCategoryList, ProductOverview, ProductDescription, ProductMetaKeywords, GREATEST(mp.ProductPrice,pp.Price) as ProductPrice, ProductSalePrice, ProductPetMedsPrice, ProductMainImage, ProductThumbnailImage, ProductWeight, ProductMinimumPrice, pp.ProjectID as ProductProjectID, (pp.ProjectID * 100000 + mp.ProductID) as DistinctID
 FROM MASTER_PRODUCT mp, PRODUCT_PROJECT pp
 WHERE pp.ProductID = mp.ProductID
 

Best Wishes,
Peter
0
Comment
Question by:freshstartusa
[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
1 Comment
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 16953110
select case when price1 > price2 then price1 else price2 end as Greatest from yourtabel
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

690 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