Я продолжаю получать сообщение о моей запятой в своем заявлении о вставке. Любая идея, почему это может быть.Почему я получаю сообщение об ошибке для моей инструкции insert?
Вот сообщение об ошибке:
Msg 102, Level 15, State 1, Line 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'
выяснил, что я добавил флаг в представление и смог упростить инструкцию insert. Спасибо всем за вашу помощь!
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'? –
Что должен делать последний 'SELECT CAST (Flag AS INT)'? Это неправильная часть ..... –
Вам необходимо ** соединить ** таблицы 'customer',' dupaddr' и 'flag' соответствующим образом, чтобы вы могли выбрать два элемента' cust_no' и ' flag' из этих объединенных таблиц - вы не можете использовать другой * подзапрос * в том месте, где вы его используете, - не работает. –