我在我的insert語句中不斷收到有關我的逗號的錯誤。任何想法,爲什麼這可能是。爲什麼我的插入語句出現錯誤?
以下是錯誤消息:
消息102,級別15,狀態1,行3
附近有語法錯誤 ''。
和INSERT INTO...SELECT
聲明
insert into custflag (cust_no, flag)
select
customer.cust_no
from
customer, dupaddr
where
customer.cust_no = dupaddr.cust_no, select cast(flag as int)
from flag
where flag_desc = 'Dup Customer'
這裏是我的查詢的全部代碼。
SET IDENTITY_INSERT flag ON
insert into flag (flag,flag_desc,available)
values ((select Max(flag) from flag) + 1, 'Dup Customer', 1)
create view dupaddr as
select distinct c1.cust_no, c1.firstname, c1.lastname, c1.company, c1.predir + ' ' + c1.streetno + ' ' + c1.streetnm + ' ' + c1.suffix + ' ' + c1.postdir as fff ,c1.address2
from customer c1,customer c2
where c1.cust_no <> c2.cust_no
and c1.firstname = c2.firstname
and c1.lastname = c2.lastname
and c1.company = c2.company
and c1.predir + ' ' + c1.streetno + ' ' + c1.streetnm + ' ' + c1.suffix + ' ' + c1.postdir = c2.predir + ' ' + c2.streetno + ' ' + c2.streetnm + ' ' + c2.suffix + ' ' + c2.postdir
and c1.address2 = c2.address2
insert into custflag (cust_no,flag)
select customer.cust_no from customer, dupaddr where customer.cust_no = dupaddr.cust_no , select cast(flag as int) from flag where flag_desc = 'Dup Customer'
琢磨出來我加了標誌的觀點,並能簡化插入語句。謝謝你們每一個人的幫助!
SET IDENTITY_INSERT flag ON
insert into flag (flag,flag_desc,available)
values ((select Max(flag) from flag) + 1, 'Dup Customer', 1)
create view dupaddr as
select distinct c1.cust_no,
c1.firstname,
c1.lastname,
c1.company,
c1.predir + ' ' + c1.streetno + ' ' + c1.streetnm + ' ' + c1.suffix + ' ' + c1.postdir as fff ,
c1.address2,
(SELECT cast(flag as int) FROM flag WHERE flag_desc = 'Dup Customer') as flag
from customer c1,customer c2
where c1.cust_no <> c2.cust_no
and c1.firstname = c2.firstname
and c1.lastname = c2.lastname
and c1.company = c2.company
and c1.predir + ' ' + c1.streetno + ' ' + c1.streetnm + ' ' + c1.suffix + ' ' + c1.postdir = c2.predir + ' ' + c2.streetno + ' ' + c2.streetnm + ' ' + c2.suffix + ' ' + c2.postdir
and c1.address2 = c2.address2
insert into custflag (cust_no,flag)
select dupaddr.cust_no, dupaddr.flag from dupaddr
這是什麼表'客戶,dupaddr之間的關係,flag'? – 2013-04-09 15:43:49
最後一個'SELECT CAST(Flag AS INT)'應該做什麼?這是錯誤的部分..... – 2013-04-09 15:51:06
您需要**以適當的方式連接**客戶,'dupaddr'和'flag'表,以便您可以選擇兩個項目'cust_no'和'來自這些連接表的「flag」 - 你不能在你使用的地方使用另一個* subquery * - 不起作用。 – 2013-04-09 15:56:54