日期:2014-05-17  浏览次数:20475 次

求高手注释已存储过程
USE [UPhoneCloud_Data]
GO
/****** Object: StoredProcedure [dbo].[U_Sp_StoresLogSeelct] Script Date: 10/12/2012 19:37:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 
ALTER PROCEDURE [dbo].[U_Sp_StoresLogSeelct] 
@UserId INT,
@StoresId INT,
@DateType INT,
@PageSize INT,
@PageIndex INT,
@Count INT OUTPUT,
@AppId INT
AS
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound=@PageSize * (@PageIndex-1)
SET @PageUpperBound=@PageLowerBound + @PageSize + 1
CREATE TABLE #TableStoresLog
(
IndexId int IDENTITY(1,1) NOT NULL,
StoresLogId int
)
DECLARE @SQL NVARCHAR(1000) 
SET @SQL='SELECT StoresLogId FROM U_StoresLog U WHERE 1=1'
IF @UserId<>0
BEGIN
SET @SQL=@SQL + ' AND UserId ='+CAST(@UserId AS NVARCHAR(50))+''
END 
IF @StoresId<>0
BEGIN
SET @SQL=@SQL + ' AND StoresId ='+CAST(@StoresId AS NVARCHAR(50))+''
END 
IF @DateType<>0
BEGIN
IF @DateType=1
BEGIN
SET @SQL=@SQL + ' AND DATEDIFF(dd,LogAddtime,GETDATE())=0'
END
IF @DateType=2
BEGIN
SET @SQL=@SQL + ' AND DATEDIFF(mm,LogAddtime,GETDATE())=0'
END
IF @DateType=3
BEGIN
SET @SQL=@SQL + ' AND DATEDIFF(wk,LogAddtime,GETDATE())=0'
END
IF @DateType=4
BEGIN
SET @SQL=@SQL + ' AND DATEDIFF(yy,LogAddtime,GETDATE())=0'
END
END 
IF @AppId<>0
BEGIN
SET @SQL=@SQL + ' AND ((AppId ='+CAST(@AppId AS NVARCHAR(50))+') OR (SELECT COUNT(StoresLogId) FROM U_StoresLog WHERE APPID='+CAST(@AppId AS NVARCHAR(50))+' AND LogLevel=U.StoresLogId )>0)'
END 
SET @SQL=@SQL +' AND LogLevel=0 ORDER BY LogAddtime DESC'
 
INSERT INTO #TableStoresLog (StoresLogId) EXEC(@SQL)
SELECT U.* FROM U_StoresLog U , #TableStoresLog WHERE U.StoresLogId=#TableStoresLog.StoresLogId
AND #TableStoresLog.IndexId>@PageLowerBound AND #TableStoresLog.IndexId<@PageUpperBound  
SELECT @Count=COUNT(StoresLogId) FROM #TableStoresLog 
RETURN @Count


------解决方案--------------------
就是一个动态SQL要注释哪个呢??