传递给LEFT或SUBSTRING函数的长度参数无效

时间:2011-03-31 07:12:22

标签: sql-server tsql

DECLARE @TotalImagesCount int
            IF(@InfoTypeiD=9)
                SET @TotalImagesCount=(SELECT ImagesCount/3 FROM Information(NOLOCK) WHERE informationid=@InformationID)
            ELSE
                SET @TotalImagesCount=(SELECT ImagesCount FROM Information(NOLOCK) WHERE informationid=@InformationID);

        SET @PageNumber = @PageNumber - 1
        SET @RowStart = @PageSize * @PageNumber + 1;
        SET @RowEnd = @RowStart + @PageSize - 1;
        BEGIN
            WITH RESULT AS
            (
                SELECT  filepath,MediaFileId,SUBSTRING(filepath,0,LEN(filepath)-3)+'_800.jpg' img800,[Description],
                SUBSTRING(filepath,0,LEN(filepath)-3)+'_1024.jpg'img1024 ,ROW_NUMBER() OVER (ORDER BY MediaFileId DESC) AS RowNumber
                --CASE WHEN  @InfoTypeID=9  THEN (SELECT COUNT(*)/3 FROM mediafile(NOLOCK) where informationid=@InformationID) 
                --ELSE (SELECT COUNT(*) FROM mediafile(NOLOCK) where informationid=@InformationID) 
                --END AS TotalImages
                FROM MediaFile(NOLOCK) WHERE InformationID=@InformationID and
                filepath NOT LIKE '%800.%' and filepath NOT LIKE '%1024.%'  
            )
            SELECT filepath,MediaFileId,img800,img1024,RowNumber,@TotalImagesCount AS TotalImages,[Description] AS ImageDescription,
            (SELECT COUNT(*) FROM RESULT) TotalRecords  FROM RESULT 
            WHERE RowNumber >= @RowStart AND RowNumber <= @RowEnd  ORDER BY MediaFileID DESC

1 个答案:

答案 0 :(得分:1)

可能是这些行:

SELECT * FROM MediaFile WHERE LEN(filepath) <= 3

另外,您确定要在SUBSTRING中使用0吗? - 请参阅http://msdn.microsoft.com/en-us/library/ms187748.aspx,尤其是评论。