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 973363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:16:04+00:00 2026-05-16T03:16:04+00:00

If I place DISTINCT keyword i get an error other wise it is working

  • 0

If I place DISTINCT keyword i get an error other wise it is working fine.

ERROR: Msg 145, Level 15, State 1, Procedure SP_Products_GetList, Line 15
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

ALTER PROCEDURE [dbo].[SP_Products_GetList]    

@CatID int,
@CatName int,
@IsNew bit,
@InActive bit,
@SortBy varchar(50),
@SortType varchar(50)

AS    

SELECT DISTINCT Products.ProductID, ProductName, MAX(Price) Price, PriceID, [Description], Size, IsNew, InActive FROM (SELECT * FROM Products WHERE (@InActive is null or @InActive = InActive  ) AND ( @IsNew is null or @IsNew = IsNew )) Products
    INNER JOIN  ProductCategory
        on Products.ProductID = ProductCategory.ProductID 
    INNER JOIN  (
                    SELECT * FROM Categories 
                        WHERE 
                            ( @CatID is null or @CatID = CatID ) and
                            ( @CatName is null or @CatName = CatName )
                ) Categories 
        on ProductCategory.CatID = Categories.CatID 
    INNER JOIN ( 
                    SELECT Prices.ProductID, Prices.Price, Prices.PriceID, Prices.SizeID  FROM Prices 
                        INNER JOIN (
                            SELECT ProductID, max(Price) Price from Prices WHERE PriceID IN 
                                    ( SELECT MAX(PriceID) FROM Prices 
                                    GROUP BY ProductID , SizeID)
                            GROUP BY ProductID )  Prices_
                        ON Prices.ProductID = Prices_.ProductID AND Prices.Price = Prices_.Price                     
                ) as Prices 
        on Prices.ProductID = Products.ProductID 
        inner join  Sizes 
        on Sizes.SizeID = Prices.SizeID 
GROUP BY ProductName, CatName, Products.ProductID, Price, PriceID, [Description] ,Size, IsNew,InActive 
ORDER BY 
CASE @SortType 
    WHEN 'desc' THEN  
    CASE @SortBy         
        WHEN 'ProductName' THEN ProductName        
        END  
    END 
    DESC, 
CASE @SortType 
    WHEN 'desc' THEN  
    CASE @SortBy         
        WHEN 'ProductID' THEN Products.ProductID
        WHEN 'Price' THEN Price          
        END  
    END 
    DESC,     
CASE @SortType 
    WHEN 'asc' THEN  
    CASE @SortBy         
        WHEN 'ProductName' THEN ProductName        
        END  
    END 
    ASC, 
CASE @SortType 
    WHEN 'asc' THEN  
    CASE @SortBy         
        WHEN 'ProductID' THEN Products.ProductID
        WHEN 'Price' THEN Price          
        END  
    END 
    ASC
  • 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-16T03:16:04+00:00Added an answer on May 16, 2026 at 3:16 am

    What happens if you do…

    SELECT ProductID, ProductName...
    FROM (
           SELECT DISTINCT Products.ProductID, ProductName...
    ) AS OrderProduct
    ORDER BY [your order code...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My place of employment is looking into buying a third party tool, for batch
I place using namespace in a view code behind but i can't call any
I'm trying to place this menu on the left hand side of the page:
Where is a good place to start with making an application in .NET that
Is there a place to find all possible uses of the syscmd method in
When I place a control on a tabpage in Silverlight the control is placed
I want to place a Webpart on a page that holds a subfolder of
My current place of employment is currently in a transition, new ownership has taken
What is the right place to store program data files which are the same
I'm trying to place 4 of my image containers into a new pane, having

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.