How to make single record from the record-set at the bottom of the list.
0. Select All
1. Apple
2. Banana
3. Mango
I need to place "Select All" at the bottom as :
1. Apple
2. Banana
3. Mango
0. Select All
Based on Id, not value .
How to make single record from the record-set at the bottom of the list.
0. Select All
1. Apple
2. Banana
3. Mango
I need to place "Select All" at the bottom as :
1. Apple
2. Banana
3. Mango
0. Select All
Based on Id, not value .
You should union a calculated sort field with a value of -ALL- with your main table and then sort the results by the calculated field.
SELECT
*
FROM
(
SELECT
RowOrder=2,
RowValue='-ALL-'
UNION
SELECT
RowOrder=1,
RowValue=FruitTable.Value
FROM
FruitTable
)AS X
ORDER BY
X.RowOrder,
x.RowValue
Please try like this.
SELECT [Values] from
(
SELECT 'Select All' [Values] UNION ALL
SELECT 'Apple' UNION ALL
SELECT 'Banana' UNION ALL
SELECT 'Mango'
)u
ORDER BY Case [Values] WHEN 'SELECT All' THEN 1 ELSE 0 END,[Values]
similar to other answers, but I assume you understand the method:
;WITH T (List, Sort) AS
(
SELECT 'Apple' , 1
UNION ALL
SELECT 'Banana' ,1
UNION ALL
SELECT 'Mango' ,1
),
T2 (List , Sort) AS
(
SELECT *
FROM T
UNION ALL
SELECT 'Select All' , 2
)
SELECT List
FROM T2
ORDER BY Sort