hello experts,
i having a below table @tbl,
DECLARE @TBL TABLE (UID INT, R_ID INT, R_NAME VARCHAR(5), R_ORD INT) INSERT INTO @TBL VALUES (1, 25, 'A', 11), 2, 25, 'B', 13), 3, 25, 'X', 5), 4, 20, 'A', 9), 5, 20, 'x', 2), 6, 21, 'A', 17), 7, 21, 'B', 14), 8, 29, 'Y', 10)
1. here as per my requirement, the "r_order" of "A" (r_name) should be greater than "r_order" of "B", please note that it is not necessary that every "r_id" have "A" & "B" as a "r_name".
2. in above set of data we have only 2 "r_id" for which we have "A" & "B", here for "r_id"21 the "r-order" is correct and for 25, incorrect.
3.we just need to swap the "r_order" for "r_id" 25? how to write update query for this?
4. Also how to get all the records having same issue as "r_id" 25? I also need a select query?
output for select query should be,
DECLARE @TBL TABLE (UID INT, R_ID INT, R_NAME VARCHAR(5), R_ORD INT) INSERT INTO @TBL VALUES (1, 25, 'A', 11), 2, 25, 'B', 13)
Thanks!