Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
If I have a string where I have character ':' which could be in any position. I would like to display only string before that character':'.How do I do this?
TG
Master Smack Fu Yak Hacker
6065 Posts
Posted - 2005-07-18 : 10:24:48
here's one way:
declare @str varchar(50)set @str = 'as;dlkfj:asldjfk'select substring(@str, 1, charindex(':', @str) - 1)EDIT:if it's possible that the ":" doesn't exist in the string:select case when charindex(':', @str) > 0 then substring(@str, 1, charindex(':', @str) - 1) else @str end
Be One with the OptimizerTG
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts
Posted - 2005-07-18 : 10:28:06
or declare @str varchar(50)set @str = 'as;dlkfj:asldjfk'left(@str,charindex(':', @str)-1)CoreyCo-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."