I have an ad-hoc query like this:Select Col1, Col2, Col3, Row_Number() Over(Order By Col1) RNFrom Tbl1Where Col2 != Col3
I'd like to loop through the results using a while loop, via T-SQL, but I'm running into a slight obstacle. I'd like to select a specific row. Now, I could make the above query a subquery and select from it, but I am concerned about performance issues and I would like to know if there is a preferred or better method.This query will return an error but I hope it will clarify my desired result, thank you:-- If this was allowed, it'd select 2nd row of data.Select Col1, Col2, Col3, Row_Number() Over(Order By Col1) RNFrom Tbl1Where Col2 != Col3 and Row_Number() Over(Order By Col1) = 2
Thank you very much for any help.