SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Scalar function help-New to tsql


Scalar function help-New to tsql

Author
Message
jonathan_blac15
jonathan_blac15
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 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!


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
GilaMonster
GilaMonster
SSC Guru
SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)SSC Guru (220K reputation)

Group: General Forum Members
Points: 220291 Visits: 46279
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search