1. Welcome Guest! In order to create a new topic or reply to an existing one, you must register first. It is easy and free. Click here to sign up now!.
    Dismiss Notice

SQL UNION-like query

Discussion in 'Microsoft News' started by NewsBot, May 24, 2008.

  1. NewsBot

    NewsBot I Got News

    Joined:
    Feb 8, 2006
    Messages:
    1,813
    Operating System:
    Windows Vista Home Premium
    I've got a table of items with prices. Nothing special really:

    CREATE TABLE Variants (
    [Name] nvarchar(50),
    [MonthlyPrice] money
    )

    I need to get a query which gets all the entries that meet all the WHERE clauses, but such that all the items with a MonthlyPrice of 0 are placed <i>below </i>the items with a price.

    So something like:

    SELECT * FROM Variants WHERE (existingClauses) AND MonthlyPrice > 0 ORDER BY [Name] ASC
    UNION
    SELECT * FROM Variants WHERE (existingClauses) AND MonthlyPrice = 0 ORDER BY [Name] ASC

    Is it possible to do it without a UNION? Because the table definition and existing clauses are already pretty complicated, and I don't want to have to duplicate the tables.




     

Share This Page