Infolink

 

Search This Blog

Jan 31, 2014

ROW_NUMBER() in SQL

Hello guys,

i have make a simple application which contains A Gridview with the thousend of records.
so i am manage it with paging.

IF I WANT TO FILTER GRIDVIEW RECORDS WITH SQL ?

So, i have take two textbox two filtering the gridview as follow.

and i am sending the value in the database as follow.

create table #tmp (id int,name varchar(10))

insert into #tmp values(1,'a')

insert into #tmp values(2,'b')
insert into #tmp values(3,'c')
insert into #tmp values(4,'d') 

select id,name,rownumber,totalrowcnt from
(
    select #tmp.*,ROW_NUMBER() over (order by #tmp.id) rownumber,count(*) over() totalrowcnt
    from #tmp
) result
where result.rownumber between VALUE1 and VALUE2
* here value1 and value2 are textbox value.

So, with this simple SQL query i can filter the gridview records.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...