troubleshooting Question

SQL Function Help

Avatar of terrydoll
terrydoll asked on
Microsoft SQL ServerSQL
10 Comments1 Solution690 ViewsLast Modified:
I have a comma delimited list of values which may be different for each record.  I would like to change those values to different values.  For example, if the value is 1,2, then I would want the value returned to be 2,55.

I am new to writing SQL functions and not sure of the proper SQL syntax.  Below is a rough example of how I think it should work, but it does not.


CREATE FUNCTION getServices
( @Val1 nvarchar(50))

RETURNS nvarchar(50)
AS
BEGIN
      DECLARE @tempServices nvarchar(50);
      CASE WHEN CHARINDEX(',1,', ',' + @Val1 + ',') > 0 THEN @tempServices = @tempServices + ',' + 2
      CASE WHEN CHARINDEX(',2,', ',' + @Val1 + ',') > 0 THEN @tempServices = @tempServices + ',' + 55

  RETURN (@tempServices)
END
go

SELECT getServices(services) AS t
FROM pff


TIA,

Terry
ASKER CERTIFIED SOLUTION
Qlemo
"Batchelor", Developer and EE Topic Advisor
Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros