Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
vijay1234
Starting Member
48 Posts |
Posted - 2014-03-17 : 14:05:18
|
Hi All,I have a function where EPN (varchar) is being used as input parameter.I have to implement if conditions based on below requirements and that should be passed to split function (space delimiter).1)Pass EPN to split function considering space as delimiter and split the string into part1, part2, part3..n etc if first part has "@" extract the characters till "@" as Name and return2)if second part contains characters "phone" or "laptop" ignore the string and take only the first part. (Ex: vijay phone --> vijay) 3)if third part contains "phone" or "laptop" ignore the string and take only the first + second part. (Ex:vijay verizon phone (or) vijay verizon laptop --> vijay verizon )4)If @ exists in concatenated string take till @. 5)if there is no @ in any part of concatenated string then all the parts (first, second, third...) as considered to be name(Ex: Vijay verizon aol --> vijay verizon aol )--check whether they satisfy automatically-- 6)if first part does not have @ and second part having @ extract the character till @ as name and return --> concatenatation of firstpart and secondpart till @ (vijay verizon@aol.com --> vijay verizon)7)if first part does not have @ and second part does not have @ and third part does not have @ then concatenate all 3 parts as name(Ex: vijay verizon aol --> vijay verizon aol) |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2014-03-18 : 00:36:40
|
For 4, 5, and 6 points,DECLARE @Str VARCHAR(100) = 'vijay verizon aol.com' -- 'vijay verizon@aol.com' SELECT CASE WHEN CHARINDEX('@', @Str) > 0 THEN SUBSTRING(@str, 1, CHARINDEX('@', @Str)-1) ELSE @Str END AS ResultStr--Chandu |
|
|
|
|
|
|
|