Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Find char in function variable

$
0
0

I have an function which return variable by replacing strings which i will be passing in my function

Branch is not in Chicago and Branch is not in Newyork and Branch is not in Dehil
Branch is in Chicago and Branch is in Mexico
Branch is not in Delhi
Branch is in Stockholm


My Function should return

Branch is not in Chicago , Newyork , Dehil
Branch is in Chicago , Mexico
Branch is not in Delhi
Branch is in Stockholm

CREATE FUNCTION [dbo].[GetRelevantCity]
(
	@GetRelevantCity  varchar(max)	
)
RETURNS varchar(max)
AS
BEGIN

	DECLARE @strVariantCondition  varchar(max)
	 set @strVariantCondition = ''
	 
	if @GetRelevantCity = '' 
		 return @strVariantCondition 
	 
		BEGIN
				set  @strVariantCondition =   LTRIM(RTRIM(CAST(@GetRelevantCity as varchar(max))))
				If @strVariantCondition <> ''  set @strVariantCondition   =  'City is '  + @strVariantCondition
		END
	RETURN @strVariantCondition 
END 


ShanmugaRaj


Viewing all articles
Browse latest Browse all 7129

Trending Articles