Solved

Trying to modify  this function in SQL that does a compare need help...

Posted on 2014-10-30
3
150 Views
Last Modified: 2014-10-30
I have this function below...
ALTER FUNCTION [dbo].[AddTwoValuesPhone](@LocId NVARCHAR(150),@DepId NVARCHAR(150))

RETURNS NVARCHAR(150)
AS
 BEGIN
        DECLARE @Result NVARCHAR(150)
        SET @Result = @LocId + ' - ' +  @DepId
        RETURN 
        (

            @Result
        )
    END

Open in new window


And what I'm trying to do it to
    What I would like to do
   
    if @Result is equal to 1 - 1 then the return result sould be this text string  = Utica/IT
   
   
    or if @Result is equal to 1 - 2 then the return result sould be this text string =  Utica/Accounting
0
Comment
Question by:yguyon28
  • 2
3 Comments
 

Author Comment

by:yguyon28
ID: 40413541
Is it possible to write something like this?

@Result
                  CASE
                   WHEN @Result = '1 - 1' THEN "Hello"
                   ELSE @Result
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40413555
Give this a whirl..
ALTER FUNCTION [dbo].[AddTwoValuesPhone] (@LocId NVARCHAR(150), @DepId NVARCHAR(150))
RETURNS NVARCHAR(150)
AS
BEGIN
   DECLARE @Result NVARCHAR(150)
   SET @Result = CASE @LocId + ' - ' +  @DepId
      WHEN '1 - 1' THEN 'Utica/IT'
      WHEN '1 - 2' THEN 'Utica/Accounting' END
   RETURN @Result
END

Open in new window


Also, just to check the box, it's normally recommented to avoid using a udf for something this simple, as udf's cannot participate in a query's execution plan, which will affect performance.
0
 

Author Closing Comment

by:yguyon28
ID: 40414016
Perfect Thank you very much....
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now