New to Telerik Test Studio? Download free 30-day trial

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:

  1. Add a SQL Database Source to the project. Here's what the sample database looks like in SQL Server Management Studio Express:

    Create DB

  2. Bind the Test to the SQL Database. Here's what the Setup Binding dialog looks like before T-SQL is enabled:

    Bind test

  3. Check Use T-SQL. Enter the following code into the T-SQL Editor section and click Update:

        SELECT TOP 1 [Name], [City], [Email], [Message]
    FROM [myDataBase].[dbo].[table]
    Where Email Like '%domain%'
    ORDER By NEWID()
    
    
    
In this article