Azure SQL Server

salilsingh-9961 346 Reputation points
2021-02-25T05:00:28.287+00:00

Hi Team, I am having a base table in sql server (say node), which has a foreign key for attribute. In another table which stores values as per attributes (using attribute foreign key), i have a reference of the base table. For a single row of base table, if it references 4 attributes, than in other table which stores attribute values, there will be 4 rows, one for each of the attribute of the base table. I want to apply multiple attribute sorting here, such that for attribute A all values to be sorted ascending and for attribute B all values to be sorted descending. This means for all rows in attribute value table where value of a particular attribute of type A are same, for same node, all attributes of type B should get sorted descending. I tried applying this using cases in order by, it is not working. It sorts rows of attribute value of both the attribute type independently. First, it sorts all type A attributes in ascending order then it sorts all type values in descending order with no relation to attribute value rows of type A. Also, node rows are repeated here, i want to get the sequence of node rows such that its corresponding rows in attribute Value table for attribute A are sorted ascending, for same node rows (no repetition of nodes), attributes of type B to be sorted descending. There could be any number of attributes with combination of asc and desc to sort. Please help me achieve this, any working example will be of great help. Thanks, Salil

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,923 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.