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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with adding http:// to a table

Author  Topic 

bjbrennan
Starting Member

2 Posts

Posted - 2006-06-09 : 21:59:08
Ok What I am looking to do is add http:// to all fields in a table that do not already begin with http://.
The query I have come up with so far is the following.
However it does not work and I am hopeing that somone that knows what they are doing can give a new guy a hand please.

UPDATE Company
SET Company.URL = 'http://' + CompanyURL
WHERE Company.CompanyURL
IN(SELECT Company.CompanyURL
FROM Company
GROUP BY Company.CompanyURL
HAVING (((NOT LEFT(Company.CompanyURL,7) = 'http://'))))

bjbrennan
Starting Member

2 Posts

Posted - 2006-06-09 : 22:04:44
Sorry I spazed after fussing with this for 15 mins already. The answer was verry simple and one of those duhhhh errors.

UPDATE Company
SET Company.CompanyURL = 'http://' + CompanyURL
WHERE Company.CompanyURL
IN(SELECT Company.CompanyURL
FROM Company
GROUP BY Company.CompanyURL
HAVING (((NOT LEFT(Company.CompanyURL,7) = 'http://'))))


Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2006-06-09 : 22:43:43
Why are you using a group by and sub select in your update statement? You could rewrite it as


UPDATE a
SET a.CompanyURL = 'http://' + a.CompanyURL
FROM Company a
WHERE a.CompanyURL NOT LIKE 'http://%'
Go to Top of Page
   

- Advertisement -