Invalid length parameter passed to the LEFT or SUBSTRING function [closed]
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.
精彩评论