作者: 唐铁明 时间: 2012-12-22 12:15
DECLARE @Page int
DECLARE @PageSize int
SET @Page = 1
SET @PageSize = 20
SET NOCOUNT ON
-- create a temp table to hold order ids
DECLARE @TempTable TABLE (IndexId int identity, _keyID VarChar(50))
-- insert the table ids and row numbers into the memory table
INSERT INTO @TempTable
(
_keyID
)
SELECT
[dbo].[X_SmsSend].[SendUser]
FROM [dbo].[X_SmsDetail]
INNER JOIN [dbo].[X_SmsSend] ON [dbo].[X_SmsDetail].[GuidId] = [dbo].[X_SmsSend].[GuidId]
WHERE 1 = @10
-- select only those rows belonging to the proper page
SELECT [dbo].[X_SmsSend].[SendUser], [dbo].[X_SmsSend].[SendTime], [dbo].[X_SmsSend].[SendContent], [dbo].[X_SmsSend].[ReceiveUName], [dbo].[X_SmsSend].[ReceiveNumber], [dbo].[X_SmsDetail].[GuidId], [dbo].[X_SmsDetail].[Reason], [dbo].[X_SmsDetail].[SendCount], [dbo].[X_SmsDetail].[SentTime]
FROM [dbo].[X_SmsDetail]
INNER JOIN [dbo].[X_SmsSend] ON [dbo].[X_SmsDetail].[GuidId] = [dbo].[X_SmsSend].[GuidId]
INNER JOIN @TempTable t ON [dbo].[X_SmsSend].[SendUser] = t._keyID
WHERE t.IndexId BETWEEN ((@Page - 1) * @PageSize + 1) AND (@Page * @PageSize)作者: 唐铁明 时间: 2012-12-22 12:17
查询出来的数据是实际数据的三倍,没办法在数据库中把表相关联的表做成了视图,通过数据库解决了,哪位知道什么问题,指导一下呀作者: 唐铁明 时间: 2012-12-22 14:41 本帖最后由 唐铁明 于 2012-12-23 03:56 编辑