Mohanrajan
Mohanrajan

Reputation: 721

How can I get particular Row in a query variable using ColdFusion?

Take the following query example:

<cfquery name="Test" Datasource = "TestDB">
    Select * from Table_Test
</cfquery>

Assume that the "Test" query returns 10 rows. I want to show single row on current time.

Note: I do not want to change the SQL statement.

Upvotes: 5

Views: 1373

Answers (2)

Scott Jibben
Scott Jibben

Reputation: 2287

If you want one random row from the query:

    <cfset start = randRange(1, Test.recordCount)>
    <cfoutput>
        #Test.name[start]#&nbsp;#Test.email[start]#<br>
    </cfoutput>

No need to loop.

NOTE: It is more efficient to modify the query to get a random row.

How to request a random row in SQL?

Upvotes: 3

CFML_Developer
CFML_Developer

Reputation: 1605

If you know your row number, Test.columnName[RowNumber] will show you the value of the columnName in specified row number.

Upvotes: 7

Related Questions