开发者

Invalid length parameter passed to the LEFT or SUBSTRING function [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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


Probably these rows:

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

Also, are you sure you want to be using 0 in your SUBSTRING? - see http://msdn.microsoft.com/en-us/library/ms187748.aspx, particularly the comments.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜