Right, I've got close to sorting this.
SELECT products.productid, products.Price,
ProdPrice = CASE products.saleprice
when 0 THEN products.price
else products.saleprice
end, products.saleprice
FROM products
where catcode=61
order by prodprice desc
Works fine apart from when I try to use CASE within the sproc to allow for choice of ORDER BY
order by
CASE WHEN @orderb = '0' THEN productid
END desc,
CASE WHEN @orderb = '1' THEN productid
END asc,
CASE WHEN @orderb = '2' THEN ProdPrice
END asc,
CASE WHEN @orderb = '3' THEN name
END asc,
CASE WHEN @orderb = '4' THEN ProdPrice
END desc,
CASE WHEN @orderb = '5' THEN name
END desc
It returns an error stating that
ProdPrice is an invalid column. It works fine with
price or
saleprice so I can only guess it has something to do with the fact that the
ProdPrice column doesn't exsist in the DB and is created in the SQL statement/sproc.
Scratching my head a little on this one.
tia
Matt