September 14, 2015 at 8:17 am
Good morning. I am trying to find all instances of a string that contain the letters FSC.
While I am able to find most of them, I am unable to find the ones wrapped in double quotes.
Query example:
Select *
from myTable
Where item like '%FSC%'
This works great with the exception of when FSC is surrounded by double quotes.
ex: MySentencecontains"FSC"
I have tried Replace with no luck.
Thanks for any assistance.
September 14, 2015 at 8:31 am
mbrady5 (9/14/2015)
Good morning. I am trying to find all instances of a string that contain the letters FSC.While I am able to find most of them, I am unable to find the ones wrapped in double quotes.
Query example:
Select *
from myTable
Where item like '%FSC%'
This works great with the exception of when FSC is surrounded by double quotes.
ex: MySentencecontains"FSC"
I have tried Replace with no luck.
Thanks for any assistance.
I suspect there is something else going on here because as posted this will work fine. Of course the leading wildcard is a performance problem but that is another topic.
if OBJECT_ID('tempdb..#Something') is not null
drop table #Something
create table #Something
(
MySentence varchar(25)
)
insert #Something
select '"FSC"'
select *
from #Something
where MySentence like '%FSC%'
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
September 14, 2015 at 8:33 am
I suspect there is a piece of info missing. Are you sure they are actually stored as double quotes.
For example try this:
DECLARE @Test TABLE(myString VARCHAR(25))
INSERT INTO @Test
VALUES ('TEST FSC'), ('MySentencecontains"FSC"')
SELECT * FROM @Test
SELECT * FROM @Test WHERE myString LIKE '%FSC%'
Both statement returns both values including the one with double quotes.
September 15, 2015 at 3:15 am
Tried with both the options below. It seems to be working fine.:-)
SELECT * FROM
(
SELECT '"DFDJFDJLKLK"FSC"' COL1
)a
WHERE COL1 like '%FSC%'
----using replace
SELECT * FROM
(
SELECT '"DFDJFDJLKLK"FSC"' COL1
)a
WHERE REPLACE(COL1,'"','') like '%FSC%'
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply