September 7, 2010 at 7:55 am
I have a list of German URLs stored in a table. Sample data:
-- Create temporary test table
CREATE TABLE #GermanURLs
(SourceURL nvarchar(1000) NULL)
-- Insert test data
INSERT INTO #GermanURLs
(SourceURL)
VALUES
('http://ww2.bafin.de/database/DealingsInfo/transaktionListe.do?cmd=loadTransaktionenAction&emittentBafinId=40002104&emittentName=118000+AG&meldepflichtigerVorname=Dr.+Klaus+&meldepflichtigerName=Harisch')
,('http://ww2.bafin.de/database/DealingsInfo/transaktionListe.do?cmd=loadTransaktionenAction&emittentBafinId=40002104&emittentName=118000+AG&meldepflichtigerVorname=Dr.+Klaus+&meldepflichtigerName=Harisch')
,('http://ww2.bafin.de/database/DealingsInfo/transaktionListe.do?cmd=loadTransaktionenAction&emittentBafinId=40002104&emittentName=118000+AG&meldepflichtigerVorname=Peter+&meldepflichtigerName=W%fcnsch')
,('http://ww2.bafin.de/database/DealingsInfo/transaktionListe.do?cmd=loadTransaktionenAction&emittentBafinId=40002104&emittentName=118000+AG&meldepflichtigerVorname=Peter+&meldepflichtigerName=W%fcnsch')
,('http://ww2.bafin.de/database/DealingsInfo/transaktionListe.do?cmd=loadTransaktionenAction&emittentBafinId=40002104&emittentName=118000+AG&meldepflichtigerVorname=Peter+&meldepflichtigerName=W%fcnsch')
,('http://ww2.bafin.de/database/DealingsInfo/transaktionListe.do?cmd=loadTransaktionenAction&emittentBafinId=99500841&emittentName=4SC+AG&meldepflichtigerVorname=Dr.+Ulrich+&meldepflichtigerName=Dauer')
As you can see characters like ü are substituted with their hexadecimal codes in the URLs, so 'Wünsch' is written as 'W%fcnsch'
I'm trying to find all the instances where a substitution has taken place by searching for the % modulo character within the SourceURL column. However, despite the modulo being present in the nvarchar SourceURL field, when I perform this search:
SELECT * FROM #GermanURLs
WHERE SourceURL LIKE '%' + ''%''+ '%'
I get this error message:
Msg 402, Level 16, State 1, Line 2
The data types varchar and varchar are incompatible in the modulo operator.
Can anyone tell me how to search for the modulo operator within an nvarchar string? If its not possible due to 'incompatability', is there another way to achieve what I'm trying to do?
September 7, 2010 at 8:07 am
This was removed by the editor as SPAM
September 7, 2010 at 8:07 am
I should step away from my desk more often - solutions always seem to pop into my head when I'm doing nothing
After an hour of looking for a solution to this online I just thought of a way to get around this when I went to the loo 🙂 SQL doesn't seem to mind the 'incompatability' if you search a string that has replaced the modulo with another character as follows (uses data from the test table mentioned above):
SELECT * FROM #GermanURLs
WHERE REPLACE(SourceURL, '%', 'THISONEHASAMODULO') LIKE '%THISONEHASAMODULO%'
September 7, 2010 at 8:08 am
stewartc - many thanks, that works nicely too 🙂 I wasn't aware of the escape command previously.
September 7, 2010 at 8:10 am
You can also go:
SELECT *
FROM #GermanURLs
WHERE SourceURL LIKE '%[%]%'
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 7, 2010 at 8:25 am
Another method
select * from #GermanURLs
where charindex('%',SourceURL)>0
Failing to plan is Planning to fail
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply