Variable in Function

  • I am working a function:

    declare @AccCharge int

    declare @zipfrom varchar

    declare @zipto varchar

    set @zipfrom ='33786'

    set @zipto = '32174'

         begin

                

    IF  @ZipFrom  in (select zip from t_RATE a join t_ZIP b ON a.state=b.state)

     

     set @AccCharge = 213

             return (@AccCharge)

            --Print (@AccCharge)

         end

    Problem is this won't return anything unless I swap the @ZipFrom in the IF statment with an actual value   IF  01234  in (select zip from t_RATE a join t_ZIP b ON a.state=b.state)

    Any ideas?

     

  • IF EXISTS (

      SELECT *  from t_RATE a

       join t_ZIP b ON a.state=b.state

       WHERE a.zip = @ZipFrom&nbsp

    BEGIN

    END

     

  • Thanks PW!  Actually my query does work. The problem I was having was I didn't specify the varchar size. It needed to be the same as the table. Thank you.

  • Yeah, if you don't specify a length for varchar it defaults to 30 chars or something obscure like that...

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply