Use T-SQL to Pull a Random Row from a SQL Database
I would like to use a single, random row of data for each execution of a test that is data bound to a SQL Database.
Solution
This is possible with T-SQL. Here's how to do it:
-
Add a SQL Database Source to the project. Here's what the sample database looks like in SQL Server Management Studio Express:
-
Bind the Test to the SQL Database. Here's what the Setup Binding dialog looks like before T-SQL is enabled:
-
Check Use T-SQL. Enter the following code into the T-SQL Editor section and click Update: