user1758545
user1758545

Reputation: 73

VBS selecting rows

How do I select a particular row from sql table. Example if value of variable is 2, then select 2nd row from table?

Is there any function in VBS to determine how many rows are in the table?

Upvotes: 0

Views: 1413

Answers (1)

Vikdor
Vikdor

Reputation: 24134

How do I select a particular row from sql table. Example if value of variable is 2, then select 2nd row from table?

You can execute the following SQL, that uses the RANK() SQL Server function to always get the second row, for example, by ordering the records by id column in DESC order:

SELECT * FROM 
(
    SELECT *, RANK() OVER (ORDER BY id DESC) 'RowRank' FROM MyTable 
) AS A
WHERE RowRank = 2

Is there any function in VBS to determine how many rows are in the table?

I am not sure if VBS has out-of-the-box function to get the number of rows in a table, but you can use a simple SQL query to find that out:

SELECT COUNT(*) FROM MyTable

This would return a value, but the query above that is selecting the second row would return a list of column values, as present in the table.

Upvotes: 1

Related Questions