sql like / where where insert语句错误

时间:2013-07-18 08:38:32

标签: sql

我想:

创建一个临时表,其中包含TBTRIGPMMCANC和TBPROPPAY上所有id_payments的列表。

从此列表中将它们从TBPROPPAY移至TBPROPPAYH。

然后从TBPROPPAY删除它们。

这是我的sql我在插入语句中有问题。我想我需要像以前一样的SQL将行移动到临时表中的每个id_payment的tbproppayh但我不知道如何写它

错误是:     E_US0AD8 INSERT:目标列数必须等于目标数         列出指定子选择中的元素。         (Thu Jul 18 09:31:23 2013)

----Clean up for IN:035466

----Description : Create a temporary table with with a list of all id_payments that are on TBTRIGPMMCANC and also TBPROPPAY.
----------------------------------------------------------------------------------------------------------------------------
DECLARE GLOBAL TEMPORARY TABLE session.set_values AS
SELECT a.id_payment FROM TBTRIGPMMCANC a, TBPROPPAY b
WHERE a.id_payment = b.id_payment 
ON COMMIT PRESERVE ROWS WITH NORECOVERY;\p\t\g


--View temporary table

SELECT * FROM session.set_values;\p\t\g
--------------------------------------------------------------

-- Description: Move list from TBPROPPAY to TBPROPPAYH
-------------------------------------------------------------
SELECT id_payment FROM session.set_values
WHERE EXISTS id_payment;\p\t\g

-- Insert into tbproppayh 
-------------------------------------------------------------
Insert into tbproppayh 
Select id_payment FROM TBTRIGPMMCANC a, TBPROPPAY b
WHERE a.id_payment = b.id_payment;\p\t\g
-------------------------------------------------------------

-- Description: DELETE list FROM tbproppay 
-------------------------------------------------------------
Delete FROM tbproppay b WHERE id_payment IN (Select a.id_payment FROM TBTRIGPMMCANC a,  TBPROPPAY b
WHERE a.id_payment = b.id_payment);\p\t\g

-------------------------------------------------------------
--Select from tbproppay & TBTRIGPMMCANC
-------------------------------------------------------------
SELECT a.id_payment FROM TBTRIGPMMCANC a, TBPROPPAY b
WHERE a.id_payment = b.id_payment;\p\t\g    
-------------------------------------------------------------

2 个答案:

答案 0 :(得分:0)

如果您想要临时表,最好使用视图。您可以获得所需的所有详细信息,然后从视图中获取。

请稍后发布代码。

你得到的错误是相当自我解释的。您为目标选择了太多列。

答案 1 :(得分:0)

如果表tbproppayh有多个列,则必须在INSERT语句中指定受影响的列:

Insert into tbproppayh (mycolumn)
Select id_payment

另一个建议,在id_payment字段之前放置别名表,否则在修复第一个错误后,你会在ambiguos字段上得到另一个错误。