-1

I have a simple function. It has not finished yet, but while doing intermediate check, I'm getting an error saying Invalid column name 'chksum1'

ALTER FUNCTION [dbo].[fnMidCheckSum]
(
    @MID varchar(16)
)
RETURNS int
AS
BEGIN

    DECLARE 
        @checkdiget int,
        @tp int,
        @chksum int,
        @chksum1 int

    set @checkdiget = 0

    select @tp = CAST(LEFT(@MID,1) AS INT) 

    if ((@tp * 2)  > 9)
    begin
        set @chksum1 = @tp * 2
        set @chksum = @chksum1 / 10
        set @chksum = @chksum + (chksum1 % 10)
    end


    RETURN @checkdiget

Cannot figure out what's wrong. Or may be my eyes just tired from the long day

gene
  • 2,098
  • 7
  • 40
  • 98

1 Answers1

0

You're missing the @ symbol in the right hand side of this statement:

set @chksum = @chksum + (chksum1 % 10)

It should be

set @chksum = @chksum + (@chksum1 % 10)
-- Here -----------------^
Mureinik
  • 297,002
  • 52
  • 306
  • 350