虽然我认为这是一个相当简单的查询,但显然存在“在‘output’附近有不正确的语法‘”。其他在线资源在调试此问题方面没有帮助。
我在这里做错什么了?
DECLARE @changes TABLE (client_id_copy INT, client_id INT);
UPDATE gmdev.contacts
SET client_id_copy=a.client_id
FROM gmdev.profile a, gmdev.contacts b
output client_id_copy, inserted.client_id into @changes
WHERE a.custid=b.custid
and NOT(Client_ID_copy > '')
and b.custid in
(select custid from gmdev.profile where custtype='EZ2');编辑:
以下建议不起作用:
DECLARE @changes TABLE (client_id_copy INT, client_id INT);
UPDATE gmdev.contacts
SET client_id_copy=a.client_id
OUTPUT client_id_copy, inserted.client_id into @changes
FROM gmdev.profile a, gmdev.contacts b
WHERE a.custid=b.custid
and NOT(Client_ID_copy > '')
and b.custid in
(select custid from gmdev.profile where custtype='EZ2');发布于 2013-06-07 14:38:21
在这种情况下,惰性系统管理员可能不会升级到最新版本的。
首先,确保运行OUTPUT支持Select @@version;关键字--这将返回如下所示的单元格:
Microsoft SQL Server 2000 - 8.00.2282 (Intel X86)
Dec 30 2008 02:22:41
Copyright (c) 1988-2003 Microsoft Corporation
Enterprise Edition on Windows NT 5.0 (Build 2195: Service Pack 4)如果结果是比Microsoft SQL Server 2005更早的,则不支持OUTPUT!
发布于 2013-06-07 13:22:37
DECLARE @changes TABLE (client_id_copy INT, client_id INT);
UPDATE gmdev.contacts
SET client_id_copy=a.client_id
output inserted.client_id_copy, inserted.client_id into @changes
FROM gmdev.profile a, gmdev.contacts b
WHERE a.custid=b.custid
and NOT(Client_ID_copy > '') -- Weird...
and b.custid in
(select custid from gmdev.profile where custtype='EZ2');发布于 2013-06-07 14:20:23
我们没有您的表和数据,所以调试任何问题对我们来说有点棘手,但是下面是编译和运行的:
create table contacts (client_id_copy int,custid int,client_id int)
create table profile(custid int,client_id int,custtype varchar(10))
DECLARE @changes TABLE (client_id_copy INT, client_id INT);
UPDATE contacts
SET client_id_copy=a.client_id
OUTPUT deleted.client_id_copy,inserted.client_id into @changes
FROM profile a, contacts b
WHERE a.custid=b.custid
and NOT(Client_ID_copy > '')
and b.custid in
(select custid from profile where custtype='EZ2');
select * from @changes不过,正如我所说的,我不知道它是否正确,因为我们不知道您的表是什么样子(我刚刚编了一些定义)。 clause中列出的每一列都必须包括相关的表名或别名(或inserted或deleted):
<column_name> ::=
{ DELETED | INSERTED | from_table_name } . { * | column_name }
| $action请注意,{ DELETED | INSERTED | from_table_name }不是标记为可选的,所以这就是为什么OUTPUT client_id_copy,不能工作。
https://stackoverflow.com/questions/16985200
复制相似问题