By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tblData(ID INT, [Type] VARCHAR (1), [OrderVal] INT);
INSERT INTO tblData(ID, [Type], [OrderVal]) VALUES
(103, 'P', 3),
(102, 'P', 1),
(101, 'P', 2);
3 rows affected
DECLARE @intPos AS INT = 0;
;WITH RowCountCte AS (
SELECT ID, ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS intPos
FROM tblData
)
SELECT @intPos = intPos FROM RowCountCte WHERE ID = 101;
SELECT COUNT(ID) AS cntRec, @intPos AS intPos
FROM tblData;
cntRec | intPos |
---|---|
3 | 3 |