Scalar function help-New to tsql

  • Hi all,

    Firstly many apologies if this is in the wrong place. I'm basicly trying to create a scalar function that returns a nvarchar (15) variable.

    The Function has two input variables namely [category] and [AreaCode] (both nvarchar(15)) with an output variable [Team Line]. I've constructed this without any problem via a case statement (see below), but as I need to use this statement repeatingly I thought a scalar function would be the answer!

    I'm new to sql functions so any good advice would be much appreciated!

    select

    ,case when

    when [Category]='A' then 'Team A'

    when [Category]='B' then 'Team B'

    when [Category]='C' then 'Team C'

    when [Category]='K' and [AreaCode] in ('Acct','Desp','Analysis') then 'Team D'

    when [Category]='L' and [AreaCode] not in ('Lark') then 'Team E'

    else 'Others'

    end as [Team Line]

    Kindest regards,

    J

  • Please don't cross post. It just wastes people's time and fragments replies.

    No replies to this thread please. Direct replies to http://www.sqlservercentral.com/Forums/Topic1490583-2799-1.aspx

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 2 posts - 1 through 1 (of 1 total)

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