Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
converting integer data type to time data type in sql 4 49
sql 2016 data tools breakdown.. 1 28
MySqli Real Escape String and SQL Injection 1 50
Replication failure 1 24
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
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 …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

730 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