A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations

后端 未结 3 634
误落风尘
误落风尘 2020-12-11 00:06

What is wrong with this statement?

ALTER Function [InvestmentReturn].[getSecurityMinLowForPeriod](@securityid int,
    @start datetime,
    @end datetime)
re         


        
3条回答
  •  再見小時候
    2020-12-11 00:13

    Column values from the SELECT statement are assigned into @low and @day local variables; the @adjustedLow value is not assigned into any variable and it causes the problem:

    The problem is here:

    select 
        top 1 @low = low
        , @day = day
        , @adjustedLow  -- causes error!
    --select high
    from 
        securityquote sq
    ...
    

    Detailed explanation and workaround: SQL Server Error Messages - Msg 141 - A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

提交回复
热议问题