By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,266 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,266 IT Pros & Developers. It's quick & easy.

TSQL Query

P: n/a
Hi All--
I have a column which contains an ID value. I also have a URL column
(within same table) which contains a NULL value, that I am trying to
update with a URL value + the value in the ID column. Here is the
update statement:
---------------------------------------------

DECLARE @URLToUpdate VARCHAR(30)
SET @URLToUpdate = (select PRI_ID from TABLE1 where URL is null)
UPDATE TABLE1 SET URL = 'http://www.fakeweb.org/maps/reports/
webtms.asp?PRI_ID=' + @URLToUpdate
where url is null
------------------------------------------------

The error message returned is:

'Subquery returned more than 1 value.'

Appreciate any help to get pointed in the right direction,
Thank You,
Aug 29 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The error is because the subquery to set @URLToUpdate returns multiple
values (as you have multiple NULL values in the URL column). Based on
your description, seems you need this query:

UPDATE Table1
SET url = 'http://www.fakeweb.org/maps/reports/webtms.asp?PRI_ID=' + id
WHERE url IS NULL;

If the ID column is numeric data type, then you can cast it:

UPDATE Table1
SET url = 'http://www.fakeweb.org/maps/reports/webtms.asp?PRI_ID=' +
CAST(id AS VARCHAR(10))
WHERE url IS NULL;
--
Plamen Ratchev
http://www.SQLStudio.com
Aug 29 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.