AndyHopper
Programmer
I'm working on a stored procedure that will split up an image into a bunch of different columns so that I can display images using a php script. This is necessary, b/c php will only return 255 characters per field.
I've been able to sucessfully generate the sql query, but it isn't executing properly. I searched the forum and google and haven't found anything pertaining to this error.
I've also been having an issue with variable scope. I need to define a variable using the EXEC(@sql) command, but it isn't letting me.
This is the error I'm getting:
Server: Msg 212, Level 16, State 1, Line 1
Expression result length exceeds the maximum. 8000 max, 8160 found.
This is the sql:
DECLARE @DataLength INT,
@bytes INT,
@i INT,
@start INT,
@sql VARCHAR(8000),
@table VARCHAR(100),
@field VARCHAR(100),
@where VARCHAR(100)
SET @table = 'NNEREN.nnerensql.dbo.idxmls1'
SET @field = 'medium_photo'
SET @where = 'id=430729'
--SET @sql = 'DECLARE @DataLength INT; SET @DataLength = (SELECT DATALENGTH(' + @field + ') as dataLength FROM ' + @table + ' WHERE ' + @where + ')'
--exec(@sql)
SET @DataLength = (SELECT DATALENGTH(medium_photo) as dataLength FROM NNEREN.nnerensql.dbo.idxmls1 WHERE id=430729)
SET @sql = 'SELECT '
SET @bytes = 0
SET @i = 0
WHILE @bytes < @DataLength
BEGIN
SET @start = @bytes
SET @bytes = @bytes + 255
SET @i = @i + 1
SET @sql = @sql + ' SUBSTRING(' + @field + ',' + convert(varchar(5),@start) + ',' +
convert(varchar(5),@bytes) + ') as col' + CONVERT(varchar(5),@i) + ','
END
SET @sql = left(@sql,len(@sql)-1)
SET @sql = @sql + ' FROM ' + @table + ' WHERE ' + @where
exec(@sql)
I've been able to sucessfully generate the sql query, but it isn't executing properly. I searched the forum and google and haven't found anything pertaining to this error.
I've also been having an issue with variable scope. I need to define a variable using the EXEC(@sql) command, but it isn't letting me.
This is the error I'm getting:
Server: Msg 212, Level 16, State 1, Line 1
Expression result length exceeds the maximum. 8000 max, 8160 found.
This is the sql:
DECLARE @DataLength INT,
@bytes INT,
@i INT,
@start INT,
@sql VARCHAR(8000),
@table VARCHAR(100),
@field VARCHAR(100),
@where VARCHAR(100)
SET @table = 'NNEREN.nnerensql.dbo.idxmls1'
SET @field = 'medium_photo'
SET @where = 'id=430729'
--SET @sql = 'DECLARE @DataLength INT; SET @DataLength = (SELECT DATALENGTH(' + @field + ') as dataLength FROM ' + @table + ' WHERE ' + @where + ')'
--exec(@sql)
SET @DataLength = (SELECT DATALENGTH(medium_photo) as dataLength FROM NNEREN.nnerensql.dbo.idxmls1 WHERE id=430729)
SET @sql = 'SELECT '
SET @bytes = 0
SET @i = 0
WHILE @bytes < @DataLength
BEGIN
SET @start = @bytes
SET @bytes = @bytes + 255
SET @i = @i + 1
SET @sql = @sql + ' SUBSTRING(' + @field + ',' + convert(varchar(5),@start) + ',' +
convert(varchar(5),@bytes) + ') as col' + CONVERT(varchar(5),@i) + ','
END
SET @sql = left(@sql,len(@sql)-1)
SET @sql = @sql + ' FROM ' + @table + ' WHERE ' + @where
exec(@sql)