在学存储过程,有一个讲光标的例子中,其中的一句不明白是什么意思,请给解释一下
就是select @chvProperty Property, @chvValue [Value], @chvUnit [Unit]这句,什么意思啊下面是例子CREATE Procedure prGetInventoryProperties_Cursor
(
@intInventoryId int,
@chvProperties varchar(8000) OUTPUT,
@debug int = 0
)Asdeclare  @intCountProperties int,
@intCounter int,
@chvProperty varchar(50),
@chvValue varchar(50),
@chvUnit varchar(50),
@insLenProperty smallint,
@insLenValue smallint,
@insLenUnit smallint,
@insLenProperties smallintSet @chvProperties = ''DECLARE @CrsrVar CURSORSET @CrsrVar = CURSOR FOR
select Property, Value, Unit
from InventoryProperty inner join Property
on InventoryProperty.PropertyId = Property.PropertyId 
where InventoryProperty.InventoryId = @intInventoryIdOPEN @CrsrVarFETCH NEXT FROM @CrsrVar
INTO @chvProperty, @chvValue, @chvUnitWHILE (@@FETCH_STATUS = 0)
BEGIN set @chvUnit = Coalesce(@chvUnit, '')        --就是下面这一句啊
        -----------------------------------------------
if @debug <> 0
select @chvProperty Property, 
@chvValue [Value], 
@chvUnit [Unit]
        -----------------------------------------------

-- check will new string fit
select @insLenProperty = DATALENGTH(@chvProperty),
@insLenValue = DATALENGTH(@chvValue),
@insLenUnit = DATALENGTH(@chvUnit),
@insLenProperties = DATALENGTH(@chvProperties) if @insLenProperties + 2 + @insLenProperty + 1 + @insLenValue + 1 + @insLenUnit > 8000
begin
select 'List of properties is too long (over 8000 characters)!'
return 1
end

-- assemble list
set @chvProperties = @chvProperties + @chvProperty + '=' + @chvValue + ' ' +  @chvUnit + '; '
if @debug <> 0
select @chvProperties chvProperties FETCH NEXT FROM @CrsrVar
INTO @chvProperty, @chvValue, @chvUnitENDCLOSE @CrsrVar
DEALLOCATE @CrsrVarreturn 0
GO

解决方案 »

  1.   

    select @chvProperty Property, @chvValue [Value], @chvUnit[Unit]
    中@chvProperty 
    @chvValue @chvUnit为要查询返回的值
    Property
    [Value], 
    [Unit]
    为列名
      

  2.   

    是不是把Property,value,unit这几个字段的值放入相关变量中?

    FETCH NEXT FROM @CrsrVar 
    INTO @chvProperty, @chvValue, @chvUnit这句不是把记录内容放到变量中吗?
      

  3.   

    select @insLenProperty = DATALENGTH(@chvProperty), 
    @insLenValue = DATALENGTH(@chvValue), 
    @insLenUnit = DATALENGTH(@chvUnit), 
    @insLenProperties = DATALENGTH(@chvProperties) 
    -------------------------------------------------
    取(@chvProperty)四个字段值的长度,付给变量@insLenProperty