我在插入语句中不断收到关于逗号的错误。关于为什么会这样的任何想法。
这是错误消息:
消息 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