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
 SQL Server 2000 Forums
 Import/Export (DTS) and Replication (2000)
 Update Statement - Need Help !!

Author  Topic 

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-08 : 22:14:06
Team,

Can you see why the following query would return this error? I am not using a subquery?



ERROR:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

The statement has been terminated.





QUERY:



UPDATE SD_INST

SET SD_INST.tme_admin_id = '1357511188.1.880#TMF_Administrator::Configuration_GUI#',

SD_INST.sd_Action = 'install (f)',

SD_INST.Exec_Time = '2000-01-01 01:00',

SD_INST.State = 'IC---',

SD_INST.Record_Time = GetDate()

FROM SD_INST ,

( SELECT M.Computer_Sys_Id, S.Inventory_Name, S.Inventory_Vers

FROM MATCH_SWARE_VIEW M INNER JOIN SD_INV S

ON M.SWARE_DESC + M.SWARE_VERS = S.Inventory_Name AND

M.Path = S.Directory_Path

) B

WHERE SD_INST.computer_sys_id = B.computer_sys_id AND

SD_INST.sware_name = B.Inventory_Name AND

SD_INST.sware_vers = B.Inventory_Vers and

SD_INST.State <> 'IC---'



Samrat

Kristen
Test

22859 Posts

Posted - 2004-11-08 : 23:01:14
No I can't! Is MATCH_SWARE_VIEW a View? Does that contain a subselect? (Can't see how that would matter though ...)

Why don't you just JOIN the stuff in the [B] sub-select to the main SD_INST table?

UPDATE SD_INST
SET SD_INST.tme_admin_id = '1357511188.1.880#TMF_Administrator::Configuration_GUI#',
SD_INST.sd_Action = 'install (f)',
SD_INST.Exec_Time = '2000-01-01 01:00',
SD_INST.State = 'IC---',
SD_INST.Record_Time = GetDate()
FROM MATCH_SWARE_VIEW M
JOIN SD_INV S
ON M.SWARE_DESC + M.SWARE_VERS = S.Inventory_Name
AND M.Path = S.Directory_Path
JOIN SD_INST
ON SD_INST.computer_sys_id = M.computer_sys_id
AND SD_INST.sware_name = S.Inventory_Name
AND SD_INST.sware_vers = S.Inventory_Vers
WHERE SD_INST.State <> 'IC---'

Kristen
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-08 : 23:18:19
I still get the similar error.

Samrat
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-08 : 23:35:51
quote:
Originally posted by samrat

Team,

Can you see why the following query would return this error? I am not using a subquery?



ERROR:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

The statement has been terminated.





QUERY:



UPDATE SD_INST

SET SD_INST.tme_admin_id = '1357511188.1.880#TMF_Administrator::Configuration_GUI#',

SD_INST.sd_Action = 'install (f)',

SD_INST.Exec_Time = '2000-01-01 01:00',

SD_INST.State = 'IC---',

SD_INST.Record_Time = GetDate()

FROM SD_INST ,

( SELECT M.Computer_Sys_Id, S.Inventory_Name, S.Inventory_Vers

FROM MATCH_SWARE_VIEW M INNER JOIN SD_INV S

ON M.SWARE_DESC + M.SWARE_VERS = S.Inventory_Name AND

M.Path = S.Directory_Path
) B

WHERE SD_INST.computer_sys_id = B.computer_sys_id AND

SD_INST.sware_name = B.Inventory_Name AND

SD_INST.sware_vers = B.Inventory_Vers and

SD_INST.State <> 'IC---'



Samrat



this is your subquery

--------------------
keeping it simple...
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-08 : 23:48:46
Yeah, but its just like a "table" isn't it? I mean, its not going to effect the UPDATE is it?

Kristen
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-08 : 23:54:47
Kristen, do you think it is some sort of a bug?

I converted my original query to the following and still got similar result

UPDATE A
SET A.tme_admin_id = '1357511188.1.880#TMF_Administrator::Configuration_GUI#',
A.sd_Action = 'install (f)',
A.Exec_Time = '2000-01-01 01:00',
A.State = 'IC---',
A.Record_Time = GetDate()
FROM SD_INST A
WHERE EXISTS ( Select 1 FROM
( SELECT M.Computer_Sys_Id, S.Inventory_Name, S.Inventory_Vers
FROM MATCH_SWARE_VIEW M
INNER JOIN SD_INV S
ON M.SWARE_DESC + M.SWARE_VERS = S.Inventory_Name AND
M.Path = S.Directory_Path
) B
WHERE A.computer_sys_id = B.computer_sys_id AND
A.sware_name = B.Inventory_Name AND
A.sware_vers = B.Inventory_Vers
)
AND A.State <> 'IC---'



Samrat
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-09 : 00:47:04
"I converted my original query to the following and still got similar result"

Did you try my suggestion with the JOIN?

Kristen
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-09 : 01:29:49
quote:
Originally posted by samrat

Kristen, do you think it is some sort of a bug?

I converted my original query to the following and still got similar result

UPDATE A
SET A.tme_admin_id = '1357511188.1.880#TMF_Administrator::Configuration_GUI#',
A.sd_Action = 'install (f)',
A.Exec_Time = '2000-01-01 01:00',
A.State = 'IC---',
A.Record_Time = GetDate()
FROM SD_INST A
WHERE EXISTS ( Select 1 FROM
( SELECT M.Computer_Sys_Id, S.Inventory_Name, S.Inventory_Vers
FROM MATCH_SWARE_VIEW M
INNER JOIN SD_INV S
ON M.SWARE_DESC + M.SWARE_VERS = S.Inventory_Name AND
M.Path = S.Directory_Path
) B
WHERE A.computer_sys_id = B.computer_sys_id AND
A.sware_name = B.Inventory_Name AND
A.sware_vers = B.Inventory_Vers
)
AND A.State <> 'IC---'



Samrat



you may want to divide your query, instead of update, use select first and see if you're updating the correct rows.

--------------------
keeping it simple...
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-09 : 04:40:59
Kirsten,

I tried the query with join and got the same error.

Jen,
If I run the query with an select it returns desired rowset. It works perfectly fine with a select.



Samrat
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-09 : 04:49:53
Does

sp_helptext 'MATCH_SWARE_VIEW'

contain a subselect?

Kristen
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-09 : 04:53:26
No it doesnot contain a subselect. The view is a inner join on 3 tables.

Samrat
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-09 : 04:58:42
I presume that SD_INV and SD_INST are tables and not views?

Any triggers on SD_INV / SD_INST, or MATCH_SWARE_VIEW, which might have some code that is getting-in-the-way?

Kristen
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-09 : 05:01:53
Yes they are tables and no triggers on any tables.

The results really surprised me, as i could do a select and would return fine but would return an error with an update.

Samrat
Go to Top of Page

samrat
Yak Posting Veteran

94 Posts

Posted - 2004-11-09 : 18:43:13
Any Luck Team, explaining this?

Samrat
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2004-11-09 : 18:48:04
Post the view.

Tara
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-11-10 : 01:13:17
from BOL
quote:

The results of an UPDATE statement are undefined if the statement includes a FROM clause that is not specified in such a way that only one value is available for each column occurrence that is updated (in other words, if the UPDATE statement is not deterministic). For example, given the UPDATE statement in the following script, both rows in table s meet the qualifications of the FROM clause in the UPDATE statement, but it is undefined which row from s is used to update the row in table t.

CREATE TABLE s (ColA INT, ColB DECIMAL(10,3))
GO
CREATE TABLE t (ColA INT PRIMARY KEY, ColB DECIMAL(10,3))
GO
INSERT INTO s VALUES(1, 10.0)
INSERT INTO s VALUES(1, 20.0)
INSERT INTO t VALUES(1, 0.0)
GO
UPDATE t
SET t.ColB = t.ColB + s.ColB
FROM t INNER JOIN s ON (t.ColA = s.ColA)
GO

The same problem can occur when combining the FROM and WHERE CURRENT OF clauses. In this example, both rows in table t2 meet the qualifications of the FROM clause in the UPDATE statement. It is undefined which row from t2 is to be used to update the row in table t1.

CREATE TABLE t1(c1 INT PRIMARY KEY, c2 INT)
GO
CREATE TABLE t2(d1 INT PRIMARY KEY, d2 INT)
GO
INSERT INTO t1 VALUES (1, 10)
INSERT INTO t2 VALUES (1, 20)
INSERT INTO t2 VALUES (2, 30)
go

DECLARE abc CURSOR LOCAL FOR
SELECT * FROM t1

OPEN abc

FETCH abc

UPDATE t1 SET c2 = c2 + d2
FROM t2
WHERE CURRENT OF abc
GO





--------------------
keeping it simple...
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-11-10 : 02:24:44
Try changing to

( SELECT MAX(M.Computer_Sys_Id) AS Computer_Sys_Id,
MAX(S.Inventory_Name) AS Inventory_Name,
MAX(S.Inventory_Vers) AS Inventory_Vers
FROM MATCH_SWARE_VIEW M INNER JOIN SD_INV S
ON M.SWARE_DESC + M.SWARE_VERS = S.Inventory_Name AND
M.Path = S.Directory_Path
) B

Kristen
Go to Top of Page
   

- Advertisement -