Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Scalar function help-New to tsql Expand / Collapse
Posted Monday, September 2, 2013 5:57 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 27, 2014 3:24 PM
Points: 6, Visits: 10
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!


,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,

Post #1490595
Posted Monday, September 2, 2013 6:01 AM



Group: General Forum Members
Last Login: Saturday, December 3, 2016 5:18 AM
Points: 45,619, Visits: 44,147
Please don't cross post. It just wastes people's time and fragments replies.

No replies to this thread please. Direct replies to

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

Post #1490597
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse