Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 Other Topics
 Derive result record set rowno given query as i/p par

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-08-31 : 10:32:50
ram writes "How do u derive the row no 'n' from a result of a query given a random query ,a random column and a random value using a fn OR a sp

Random query might have an order by clause

Say the output of the random input query on a table results into a record set below

col1 col2 col3
----------------
a a1 a2
b b1 b2
c c1 c2

and if random inputs --> colinput = col2 and colvalinput = b1 are provided
then the output of the fn should be 2 --indicating the position on the row where value b1 is ."

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-01 : 17:58:58
[code]-- prepare test data
declare @test table (col1 varchar(2), col2 varchar(2), col3 varchar(2))

insert @test
select 'a', 'a1', 'a2' union all
select 'b', 'b1', 'b2' union all
select 'c', 'c1', 'c2'

-- show the row for b1 value in col2
select count(*)
from @test
where col2 <= 'b1'[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -