Solved

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

Posted on 2014-10-30
3
143 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 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

25 Experts available now in Live!

Get 1:1 Help Now