pilotboba wrote:
Otis wrote:
Yes I know, but I wanted to understand the semantic value of that, as I don't see it yet (understand it yet)
(and by understanding the semantic value I mean: so I can give an alternative perhaps)
I see. He could probably just add a calculated field to his table, or create a view to solve this problem though.
I’ll now try to be more explicit,
Definition of Table1:
CREATE TABLE [dbo].[Table1] (
[A] [int] NULL ,
[B] [int] NOT NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[Table1] WITH NOCHECK ADD
CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED
(
[B]
) ON [PRIMARY]
Column B is primary key, Column A value is NULL in case of root entry (root entry is row without superior row) or it holds superiors row primary key value. Superior row is always root entry. In the given example rows with PK values 1, 2, 3 are root entries and row with PK value 4 has superior entry with PK value 1. Entries with PK 1 and 4 are linked in the sense that row 1 is root entry and row 4 has 1 as its superior.
In the following code block is query without order clause and query result:
SELECT A, B
FROM TABLE1
A B
----------- -----------
NULL 1
NULL 2
NULL 3
1 4
(4 row(s) affected)
In the following code block is query with order clause and query result:
SELECT A, B
FROM TABLE1
ORDER BY ISNULL (A, B)
A B
----------- -----------
NULL 1
1 4
NULL 2
NULL 3
(4 row(s) affected)
Purpose of order clause in the given query is to sort rows by root entry row followed by rows which have that root row as superior.
Any suggestions how to write SortExpression?
Thanks,
Vlada