Thanks for your attention.
Finally, I discovered the answer.
I should use ORDER BY like this:
ORDER BY (SELECT top(1) Value from @list li where mytable.id = li.id)
Just one more question:
Is it possible to select this Value and have this column next to columns of my table? For example, Imagine we have:
*****************************************
Data in my user defined table type:
ID / Value
4 / 30
1 / 20
3 / 10
*****************************************
Data in my table:
id / name
1 / a
2 / b
3 / c
4 / d
*****************************************
The out put with this query will be:
id / name
4 / d
1 / a
3 / c
*****************************************
I sit possible to have this out put?
id / name / Value
4 / d / 30
1 / a / 20
3 / c / 10
*****************************************
As I know, if my user defined table type was a table, I could Right Join this with my table to achieve this. But, I don`t want to create a table. Is it possible?
*******************************************************************************
Answer:
Yes,It is possible. For solving first and second question, we need to write this query:
select my.id, my.name, li.value
from mytable my
join @list li
on my.id = li.id
order by li.value
In my codes, I should alter my procedure in this way:
ALTER PROCEDURE [dbo].[DoSomethingWithCandidates]
@List AS dbo.CandidateList READONLY
AS
BEGIN
SET NOCOUNT ON;
SELECT mytable.*, li.Score
FROM tblspecifications mytable
join @List li
on mytable.id = li.id
ORDER BY li.Score desc
END
Good Luck.