28

I want to write a comparation procedure (t-sql) for site seo.

I have a table with field 'url' (nvarchar()) that contain a part of site url's. Ex: 'mysyte.com/?id=2'. Also this table for each url contains metadata, that i need to extract.

The main problem is that full url on site looks like 'mysyte.com/?id=2&region=0&page=1', and i just need to ignore everething, except url in table:

I mean: 'mysyte.com/?id=2' => is a part of 'mysyte.com/?id=2&region=0&page=1'

gbn
  • 422,506
  • 82
  • 585
  • 676
Maxim
  • 1,555
  • 5
  • 18
  • 28

3 Answers3

85

You can use the LIKE operator to compare the content of a T-SQL string, e.g.

SELECT * FROM [table] WHERE [field] LIKE '%stringtosearchfor%'

The percent character '%' is a wild card- in this case it says return any records where [field] at least contains the value "stringtosearchfor".

Josh Correia
  • 3,807
  • 3
  • 33
  • 50
WiseGuyEh
  • 18,584
  • 1
  • 20
  • 20
7
SELECT *
FROM myTable
WHERE URL = LEFT('mysyte.com/?id=2&region=0&page=1', LEN(URL))

Or use CHARINDEX http://msdn.microsoft.com/en-us/library/aa258228(v=SQL.80).aspx

Jonathan
  • 5,953
  • 1
  • 26
  • 35
6

you can use CHARINDEX in t-sql.

select * from table where CHARINDEX(url, 'http://url.com/url?url...') > 0

chris
  • 9,745
  • 1
  • 27
  • 27