Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 由于错误,我无法使用此查询将新记录插入表中_Sql_Sql Server - Fatal编程技术网

Sql 由于错误,我无法使用此查询将新记录插入表中

Sql 由于错误,我无法使用此查询将新记录插入表中,sql,sql-server,Sql,Sql Server,我的目标是只插入新记录来更新我刚刚创建的表,但它会给我一条错误消息102,如下所示。当我点亮或单击SSMS中错误消息区域上的错误消息时。它突出显示脚本的ss.sitedesc=b.sitedesc部分。我看不出有什么问题。有人能帮我吗?多谢各位 Msg 102,15级,状态1,第39行 “ss”附近的语法不正确 这是我目前的全部剧本 insert into SEC_ODS.dbo.ODSCustomerBase select --Identity as CustomerBaseID

我的目标是只插入新记录来更新我刚刚创建的表,但它会给我一条错误消息102,如下所示。当我点亮或单击SSMS中错误消息区域上的错误消息时。它突出显示脚本的ss.sitedesc=b.sitedesc部分。我看不出有什么问题。有人能帮我吗?多谢各位

Msg 102,15级,状态1,第39行 “ss”附近的语法不正确

这是我目前的全部剧本

insert into SEC_ODS.dbo.ODSCustomerBase    
select 
--Identity as CustomerBaseID
'E4SE' as Recordsource, 
'C' as RecordType, 
ss.siteURN,
ss.sitedesc,
ss.FS_URL + 'frmcustomer.aspx?CustomerID=' + customerid as CustomerLink,
co.HomeCurrencyCode, 
c.customerid, 
c.currencycode as customercurrencycode,
c.entityname as CustomerName, 
c.entityshortname CustomerShortName, 
c.address, 
c.city, 
c.postalcode, 
c.countrycode, 
cn.countryname, 
c.statecode,
s.statename, 
c.phone,
c.fax, 
c.taxcode, 
c.prospectid,
c.createdate, 
c.lastupdatedate 
from country cn, 
SECSite ss, 
company co, 
customer c 
left outer join state s 
on c.statecode = s.statecode
where  ss.LocalSiteFlag = 1
and cn.countrycode = c.countrycode

and not exists(select * from SEC_ODS.dbo.ODSCustomerBase b
                where(ss.siteURN=b.siteURN
                      ss.sitedesc=b.sitedesc
                      ss.FS_URL=b.FS_URL
                      co.HomeCurrencyCode=b.HomeCurrencyCode
                      c.customerid=b.customerid
                      c.currencycode=b.currencycode
                      c.entityname=b.entityname
                      c.entityshortname=b.entityshortname
                      c.address=b.address
                      c.city=b.city
                      c.postalcode=b.postalcode
                      c.countrycode=b.countrycode
                      cn.countryname=b.countryname
                      c.statecode=b.statecode
                      s.statename=b.statename
                      c.phone=b.phone
                      c.fax=b.fax
                      c.taxcode=b.taxcode
                      c.prospectid=b.prospectid
                      c.createdate=b.createdate
                      c.lastupdatedate=b.lastupdatedate))
但是当我把它放在where条件下

它会提示我以下无效列的错误

这是我用来创建表的脚本。这可能会有帮助

USE SEC_ODS
GO 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[ODSCustomerBase]') AND type in (N'U'))
DROP TABLE [ODSCustomerBase]
Go
Create Table ODSCustomerBase
(CustomerBaseID             int NOT NULL identity primary key,
RecordSource            nvarchar(4),
RecordType              varchar(2),
SiteURN             nvarchar(128)NOT NULL,
SiteDesc                    nvarchar(60)NULL,
CustomerLink            nvarchar(120)NOT NULL,
HomeCurrencyCode            nvarchar(8)NOT NULL, 
CustomerID                  nvarchar(15)NOT NULL,
CustomerCurrencyCode        nvarchar(8)NOT NULL,
CustomerName            nvarchar(120)NULL,
CustomerShortName           nvarchar(30) NOT NULL,
Address             nvarchar(255)NULL,
City                    nvarchar(25)NULL,
PostalCode              nvarchar(10) NULL,
CountryCode             nvarchar(3) NOT NULL,
CountryName             nvarchar(60) NOT NULL,
StateCode               nvarchar(8) NULL,
StateName               nvarchar(60) NULL,
Phone                   nvarchar(30) NOT NULL,
Fax                 nvarchar(30) NULL,
TaxCode             nvarchar(15) NULL,
ProspectID              nvarchar(15) NULL,
CreateDate              datetime NOT NULL,
LastUpdateDate          datetime NULL)

语句之间应该有一个逻辑运算符。像这样:

... ss.siteURN=b.siteURN
                  ss.sitedesc=b.sitedesc AND
                  ss.FS_URL=b.FS_URL AND
                  co.HomeCurrencyCode=b.HomeCurrencyCode AND
                  c.customerid=b.customerid  ...

在where子句中,您可能会错过AND关键字

where(ss.siteURN=b.siteURN
                AND  ss.sitedesc=b.sitedesc
                AND  ss.FS_URL=b.FS_URL

…请阅读插入查询的syntex,如: 插入tablename(ColumnName1,columnname2,…)值(value1,valkue2,…)

因此,您的查询如下所示,您需要根据表列名更改columnname:

insert into SEC_ODS.dbo.ODSCustomerBase(columnname1, columnname2, ...)    
select 
--Identity as CustomerBaseID
'E4SE' as Recordsource, 
'C' as RecordType, 
ss.siteURN,
ss.sitedesc,
ss.FS_URL + 'frmcustomer.aspx?CustomerID=' + customerid as CustomerLink,
co.HomeCurrencyCode, 
c.customerid, 
c.currencycode as customercurrencycode,
c.entityname as CustomerName, 
c.entityshortname CustomerShortName, 
c.address, 
c.city, 
c.postalcode, 
c.countrycode, 
cn.countryname, 
c.statecode,
s.statename, 
c.phone,
c.fax, 
c.taxcode, 
c.prospectid,
c.createdate, 
c.lastupdatedate 
from country cn, 
SECSite ss, 
company co, 
customer c 
left outer join state s 
on c.statecode = s.statecode
where  ss.LocalSiteFlag = 1
and cn.countrycode = c.countrycode
and not exists(select columnaname3 from SEC_ODS.dbo.ODSCustomerBase b
                where(ss.siteURN=b.siteURN  and
                      ss.sitedesc=b.sitedesc  and
                      ss.FS_URL=b.FS_URL  and
                      co.HomeCurrencyCode=b.HomeCurrencyCode  and
                      c.customerid=b.customerid  and
                      c.currencycode=b.currencycode  and
                      c.entityname=b.entityname  and
                      c.entityshortname=b.entityshortname  and
                      c.address=b.address  and
                      c.city=b.city  and
                      c.postalcode=b.postalcode  and
                      c.countrycode=b.countrycode  and
                      cn.countryname=b.countryname  and
                      c.statecode=b.statecode  and
                      s.statename=b.statename  and
                      c.phone=b.phone  and
                      c.fax=b.fax  and
                      c.taxcode=b.taxcode  and
                      c.prospectid=b.prospectid  and
                      c.createdate=b.createdate  and
                      c.lastupdatedate=b.lastupdatedate))

嗨,Jokey。在我使用别名的列上仍然有一些错误。看起来您的表“SECSite”不包含列“FS\u URL”。还要检查“currencycode”、“entityname”和“entityshortname”列。