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®ion=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®ion=0&page=1'
SQL Server CHARINDEX() Function The CHARINDEX() function searches for a substring in a string, and returns the position. If the substring is not found, this function returns 0. Note: This function performs a case-insensitive search.
CONTAINS is a predicate used in the WHERE clause of a Transact-SQL SELECT statement to perform SQL Server full-text search on full-text indexed columns containing character-based data types. CONTAINS can search for: A word or phrase. The prefix of a word or phrase.
The SUBSTRING() function extracts a substring from a string (starting at any position).
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".
SELECT *
FROM myTable
WHERE URL = LEFT('mysyte.com/?id=2®ion=0&page=1', LEN(URL))
Or use CHARINDEX http://msdn.microsoft.com/en-us/library/aa258228(v=SQL.80).aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With