Hello, I get the following error when running my select statement but all the order by columns are in the select...
RDER BY items must appear in the select list if SELECT DISTINCT is specified.
Select Distinct Top 20 (productid) as ProductId, title, ITEM_RANK, price from #Temp
Order by case when @SortBy = 'Title' then Title when @sortby = '' then Title end
, case when @SortBy = 'Price' then Price when @sortby = '' then Price end
, case when @SortBy = 'BestSeller' then ITEM_RANK when @sortby = '' then ITEM_RANK
How to repair my statement?