ALTER PROCEDURE [dbo].[Proc_XXGL_QCCXXT]
-- Add the parameters for the stored procedure here
@DWDM varchar(2000),
@JCZ varchar (50),
@ZZXM varchar (8),
@DJH varchar(50),
@PageSize int,
@PageID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @XM varchar(8)
DECLARE @StateMent VARCHAR(400)
DECLARE @SQL VARCHAR(1000)
DECLARE @ORDERBY VARCHAR(50)
DECLARE @COUNT_SQL VARCHAR(500)
SET @StateMent=''
SET @SQL = ''
SET @ORDERBY = ' ORDER BY DJH'
IF OBJECT_ID('TEMPDB..#TempTable_XXGL_QCCXXT') IS NOT NULL
BEGIN
DROP TABLE #TempTable_XXGL_QCCXXT
END
CREATE TABLE #TempTable_XXGL_QCCXXT
(
[ID] [INT] IDENTITY (1,1) NOT NULL,
[DJH] [VARCHAR] (50) NOT NULL,
[XM] [VARCHAR] (50) NULL,
[DWMC] [VARCHAR] (50) NULL,
[DJRQ][VARCHAR] (50) NULL,
[CLRQ] [VARCHAR] (16) NULL
)
IF(@Dwdm != '-1') BEGIN
SET @StateMent = @StateMent + ' AND a.Dwdm in ('+ @Dwdm + ')'
END
IF(@DJH <> '' AND @DJH IS NOT NULL) BEGIN
SET @StateMent = @StateMent + ' AND DJH LIKE ''%' + @DJH + '%'''
END
SET @SQL = 'INSERT INTO #TempTable_XXGL_QCCXXT
SELECT TOP ' + cast(@PageID * @PageSize as varchar(20)) + ' DJH,XM,B.DWMC,DJRQ ,CLRQ
FROM
XXGL_QCTEAM as A
LEFT JOIN XXGL_QCTEAM AS B ON A.DWDM = B.DWDM left join XXGL_QCTEAM c on
WHERE 1 = 1 ' + '@StateMent'
+ @ORDERBY
PRINT(@SQL)
EXEC(@SQL)
SET @COUNT_SQL = 'SELECT COUNT(*)
FROM XXGL_QCTEAM as A WHERE 1 = 1 ' + @StateMent
print(@COUNT_SQL)
EXEC(@COUNT_SQL)
IF(@pageID<=1) BEGIN
SET @SQL = 'SELECT TOP ' + CAST(@pagesize AS VARCHAR(10)) + ' * FROM #TempTable_XXGL_QCCXXT'
END
ELSE BEGIN
SET @SQL = 'SELECT TOP ' + CAST(@pagesize AS VARCHAR(10)) + ' * FROM #TempTable_XXGL_QCCXXT'
SET @SQL = @SQL + ' WHERE [ID] > ' + CAST(@pagesize * (@pageID - 1) AS VARCHAR(10))
END
EXECUTE(@SQL)
DROP TABLE #TempTable_XXGL_QCCXXT
END
帮我看看这个写的哪不对谢谢
新手