Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I'm write a stored procedure where i want to display null values at the bottom of
each department.

Scenario
------------------------------------
ID | Name           | cost | Dept  |
---|----------------|------|-------|
1  | a              |  15  |  1    |
2  | b              |  10  |  1    |
nul| Total          |  25  |       |
5  | c              |  5   |  2    |
nul| Total          |  5   |       |
7  | d              |  2   |  3    |
nul| Total          |  2   |       |
------------------------------------



in @tbl i'm fetch all the values from the order table
n
in @tbl2 i'm fetching the total of sum(cost) using group by dept.

then i have used union all

select * from @tbl
union all
select * from @tbl1

This one is displaying null values first values, order by dept.

But i want to display first values then null values,
order by dept(eg. as above table).

can any one please help me to get this table in sql where i can display null values
at the bottom of each department.


Thanks
Posted

1 solution

Add:
SQL
ORDER BY ISNULL(Dept, -1) DESC
 
Share this answer
 
Comments
abdul subhan mohammed 12-Dec-15 4:15am    
All Null values coming at most bottom of the table.
But i'm looking something like what i have drawn in the scenario table.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900