Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 258797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:12:37+00:00 2026-05-11T22:12:37+00:00

Example Schema: RowID Quantity ModifiedPrice GroupPrice CustomPrice SalePrice —————————————————————————- 1 5 20.00 0 15.00

  • 0

Example Schema:

RowID    Quantity    ModifiedPrice    GroupPrice    CustomPrice    SalePrice
----------------------------------------------------------------------------
1        5           20.00            0             15.00          17.00
2        2           14.00            7.00          22.00          0
3        9           10.00            10.00         0              11.00

Based on this example table, I would like to be able to select the lowest non-zero value between the four *Price columns in the most efficient/simplest manner possible.

Example Output:

RowID    Quantity    EndPrice
------------------------------
1        5           15.00
2        2           7.00
3        9           10.00

For extra information, the DB is SQL Server 2005.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:12:38+00:00Added an answer on May 11, 2026 at 10:12 pm
    SELECT  RowId, Quantity,
            (
            SELECT  MIN(price)
            FROM    (
                    SELECT  ModifiedPrice AS price
                    UNION ALL
                    SELECT  GroupPrice
                    UNION ALL
                    SELECT  CustomPrice
                    UNION ALL
                    SELECT  SalePrice
                    ) qi
            WHERE   price > 0
            )
    FROM    mytable
    

    This is more readable than a bunch of CASE statements.

    Note however that this is about 4 times as slow as CASE statements.

    Here’s the test script which parses and yields correct results:

    CREATE TABLE #t_prices
            (
            RowID INT NOT NULL,
            Quantity INT NOT NULL,
            ModifiedPrice FLOAT NOT NULL,
            GroupPrice FLOAT NOT NULL,
            CustomPrice FLOAT NOT NULL,
            SalePrice FLOAT NOT NULL
            )
    
    INSERT
    INTO    #t_prices
    VALUES  (1, 5, 20.00, 0, 15.00, 17.00)
    INSERT
    INTO    #t_prices
    VALUES  (2, 2, 14.00, 7.00, 22.00, 0)
    INSERT
    INTO    #t_prices
    VALUES  (3, 9, 10.00, 10.00, 0, 11.000)
    
    
    SELECT  RowId, Quantity,
            (
            SELECT  MIN(price)
            FROM    (
                    SELECT  ModifiedPrice AS price
                    UNION ALL
                    SELECT  GroupPrice
                    UNION ALL
                    SELECT  CustomPrice
                    UNION ALL
                    SELECT  SalePrice
                    ) qi
            WHERE   price > 0
            )
    FROM    #t_prices
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an example schema like: id:1,date:2012-05-01,parent:p1 id:1,date:2012-05-01,parent:p2 id:1,date:2012-05-01,parent:p3 id:1,date:2012-05-02,parent:p1 id:1,date:2012-05-02,parent:p4 I would like
this is an example: table mysql schema : id name salary 1 david 20
I have URL scheme for my blog like this: http://www.example.com/%YEAR%/%MONTH%/%CATEGORY%/%POST_TITLE%/ Now i want to
I've got 3 tables: Schema: For example, I have data like: 1> select id,
I found this tsql query that shows the xml schema of a table and
Using the Northwind schema as an example which collection interface would you use in
This is a simplified example of the actual schema, so please bear with me.
I would like to add some custom elements to a mule flow, like this:
Assume a Doctrine model Profile : # This is example of my schema.yml Profile:
In example apps database is in most cases single table, so db schema is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.