Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Scalar function help-New to tsql Expand / Collapse
Author
Message
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: Monday, September 2, 2013 8:54 AM
Points: 3, Visits: 7
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
Post #1490595
Posted Monday, September 2, 2013 6:01 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 4:54 PM
Points: 42,434, Visits: 35,488
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 2008, MVP
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