Simple question:
In the query
Code:
SELECT Value, 'DummyValue' = IncrementingVariable FROM Table
How can you order by 'DummyValue'?
Same question, but with the way I need it...
In the query
Code:
DECLARE @Client_Code varchar(30)
DECLARE @Campaign_Code varchar(30)
DECLARE @Catalogue_ID int
DECLARE @Section_ID int
DECLARE @Points int
DECLARE @Country_Code int
DECLARE @SortOrder int
SET @Client_Code = 'XQX'
SET @Campaign_Code = 'DEM'
SET @Catalogue_ID = '151'
SET @Section_ID = '177'
SET @Points = '999999'
SET @Country_Code = '1'
SET @SortOrder = '1'
SELECT Products.ID, Products.Name, 'Points' =
CASE
WHEN EXISTS (
SELECT cPoints_Value FROM tblAward_Value WITH (NOLOCK)
WHERE cAward_Code = Products.ID
AND cClient_Code = @Client_Code
AND cCampaign_Code = @Campaign_Code
AND cCountry_Code = @Country_Code
AND cPoints_Value = @Points)
THEN (SELECT cPoints_Value FROM tblAward_Value WITH (NOLOCK)
WHERE cAward_Code = Products.ID
AND cClient_Code = @Client_Code
AND cCampaign_Code = @Campaign_Code
AND cCountry_Code = @Country_Code
AND cPoints_Value = @Points)
ELSE (SELECT cPoints_Value FROM tblAward_Value WITH (NOLOCK)
WHERE cAward_Code = Products.ID
AND cClient_Code = 'PMM'
AND cCampaign_Code = 'PMM'
AND cCountry_Code = @Country_Code
AND cPoints_Value = @Points)
END
FROM Products
INNER JOIN Product_Display ON Products.ID = Product_Display.Product_ID
WHERE Product_Display.Client_Code LIKE @Client_Code
AND Product_Display.Campaign_Code LIKE @Campaign_Code
AND Product_Display.Catalogue_ID = @Catalogue_ID
AND Product_Display.Section_ID = @Section_ID
ORDER BY CASE @SortOrder -- varchar fields
WHEN 1 THEN Products.Name
ELSE Products.Name
END
How can you order by 'Points'?
TIA