随笔 - 58  文章 - 14 评论 - 10 trackbacks - 0
<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

与我联系

搜索

 

常用链接

留言簿

我参加的小组

随笔档案(58)

文章分类(11)

Watch

最新评论

阅读排行榜

评论排行榜

For retrieving the middle rows of a table irrespective of its columns needs to write a procedure which will take 3 parameters.

First parameter: The first parameter is the query of the particular table with respective column names (if needed or if u know the column details) otherwise u can give the * instead of column names with respective where condition in it, the parameter is of data type TEXT.

Second parameter: This parameter will take int value which is used to take values from the row where you want to start retrieving data.

Third parameter: This parameter also will take int value which is used to take values till which row you want retrieve data.

CREATE PROCEDURE sp_MidRows_Query(@Qry TEXT, @from INT, @to INT)
AS
BEGIN
DROP TABLE ##newTbl
DROP TABLE ##tbl
EXEC('SELECT * INTO ##newTbl FROM ('+@Qry+') temp')
SELECT * INTO ##tbl FROM ##newTbl
ALTER TABLE ##tbl ADD Sno INT IDENTITY(1,1)
SELECT * INTO #tbl FROM ##tbl
SELECT * FROM #tbl WHERE Sno BETWEEN @from AND @to
END

In this procedure Global variable table is used to store the data that is retrieved from the table.

Example for this procedure:

sp_MidRows_Query SELECT * FROM Employee WHERE Salary > 10000 , 4, 9

First parameter is SELECT * FROM Employee WHERE Salary > 10000

Second parameter is 4

Third parameter is 9

This will give the list of employees whose salary is greater than 10000 and also from 4th row to 9th row.

posted on 2008-04-28 09:55 josephshi 阅读(21) 评论(0)  编辑 收藏

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: