存储过程怎么反回@Result结果为空
CREATE PROCEDURE 存储过程名
@Result VARCHAR(8000) OUTPUT
AS
DECLARE @id INT
DECLARE @Str VARCHAR(8000)
DECLARE Cur CURSOR FOR SELECT [id] FROM [表]
OPEN Cur
WHILE @@FETCH_STATUS=0
BEGIN
FETCH NEXT FROM Cur INTO @id
SET @Str=@Str+','+@id
END
CLOSE Cur
DEALLOCATE Cur
SET @Result=@Str
GO
怎么反回@Result结果为空
------解决方案--------------------你给@Str赋一个0,没赋初值是null
------解决方案--------------------CREATE PROCEDURE 存储过程名
@Result VARCHAR(8000) OUTPUT
AS
DECLARE @id INT
DECLARE @Str VARCHAR(8000)
set @Str=''
DECLARE Cur CURSOR FOR SELECT [id] FROM [表]
OPEN Cur
WHILE @@FETCH_STATUS=0
BEGIN
FETCH NEXT FROM Cur INTO @id
SET @Str=@Str+','+@id
END
CLOSE Cur
DEALLOCATE Cur
SET @Result=@Str
GO
------解决方案--------------------CREATE PROCEDURE 存储过程名
@Result VARCHAR(8000) OUTPUT
AS
DECLARE @id INT
DECLARE @Str VARCHAR(8000)
DECLARE Cur CURSOR FOR SELECT [id] FROM [表]
OPEN Cur
set @Str =''
FETCH NEXT FROM Cur INTO @id
WHILE @@FETCH_STATUS=0
BEGIN
FETCH NEXT FROM Cur INTO @id
SET @Str=@Str+','+@id
END
CLOSE Cur
DEALLOCATE Cur
SET @Result=@Str
GO
------解决方案--------------------CREATE PROCEDURE 存储过程名
@Result VARCHAR(8000) OUTPUT
AS
DECLARE @Str VARCHAR(8000)
SELECT @Str=ISNULL(@Str,',')+LTRIM([id])+',' FROM [表]
SET @Result=@Str
GO
------解决方案--------------------定义后先赋值,set @Str=''