我正在修改一个连接某些表并返回输出的存储过程。我想要包含一个将执行连接操作的新表以及那些现有表。虽然这样做我得到一个“消息4104”,同时包括这个条件。我看到它是在select语句中的别名问题,但我是存储过程的新手,无法弄清楚它是如何发生的。我发布我的代码请有人帮忙。这是我正在开发的代码的一部分
CREATE TABLE #es_ediconsolidate
(
[txtype] [CHAR](2) NULL,
[txdesc] [VARCHAR](40) NULL,
[txrefno] [CHAR](25) NULL,
[clntcode] [CHAR](5) NULL,
[polno] [CHAR](10) NULL,
[certno] [CHAR](10) NULL,
[depcode] [DECIMAL](5, 0) NULL,
[deptype] [CHAR](1) NULL,
[namefirst] [CHAR](50) NULL,
[namelast] [CHAR](50) NULL,
[namemid] [CHAR](2) NULL,
[inieffdt] [DATETIME] NULL,
[status] [CHAR](1) NULL,
[chgeffdt] [DATETIME] NULL,
[suboffcode] [CHAR](3) NULL,
[departcd] [CHAR](6) NULL,
[memidno] [CHAR](12) NULL,
[dob] [DATETIME] NULL,
[sex] [CHAR](1) NULL,
[marital] [CHAR](1) NULL,
[occupation] [CHAR](20) NULL,
[empno] [CHAR](10) NULL,
[empdt] [DATETIME] NULL,
[salary] [DECIMAL](13, 2) NULL,
[bankac] [CHAR](40) NULL,
[memnation] [CHAR](3) NULL,
[effdate] [DATETIME] NULL,
[bankcode] [CHAR](4) NULL,
[salarymode] [CHAR](1) NULL,
[bankactype] [CHAR](1) NULL,
[bankaceffdate] [DATETIME] NULL,
[bankacstatus] [CHAR](1) NULL,
[firstcovdt] [DATETIME] NULL,
[maxageexemptind] [CHAR](1) NULL,
[vipstatus] [CHAR](1) NULL,
[sponsoridno] [VARCHAR](20) NULL,
[passportno] [CHAR](15) NULL,
[nationalidno] [CHAR](30) NULL,
[bankname] [CHAR](40) NULL,
[branchname] [CHAR](40) NULL,
[branchaddress] [CHAR](40) NULL,
[bankcurrency] [CHAR](3) NULL,
[swiftcode] [CHAR](15) NULL,
[servicedeskid] [CHAR](10) NULL,
[servicedeskdate] [DATETIME] NULL,
[dmpindicator] [CHAR](1) NULL,
[salarychgeffdt] [DATETIME] NULL,
[studentind] [CHAR](1) NULL,
[outcntyind] [CHAR](1) NULL,
[prodcode] [CHAR](5) NULL,
[benplncd] [CHAR](3) NULL,
[covgcode] [CHAR](5) NULL,
[proposedsa] [DECIMAL](11, 0) NULL,
[prdstatus] [CHAR](1) NULL,
[benid] [CHAR](20) NULL,
[benname] [CHAR](40) NULL,
[benrelat] [CHAR](15) NULL,
[beneffdt] [DATETIME] NULL,
[benshare] [DECIMAL](5, 4) NULL,
[remark] [CHAR](16) NULL,
[rcdsts] [CHAR](1) NULL,
[rcdusrid] [CHAR](20) NULL,
[rcddtstmp] [DATETIME] NULL,
[txstatus] [CHAR](1) NULL,
[uploadusrid] [VARCHAR](20) NULL,
[uploadtime] [DATETIME] NULL,
[errorcode] [CHAR](6) NULL,
[errormsg] [VARCHAR](100) NULL,
[isprocessing] [CHAR](1) NULL,
[parentclient] [VARCHAR](40) NULL,
[agentname] [VARCHAR](101) NULL,
[packagecode] [CHAR](35) NULL,
[province] [CHAR](20) NULL,
[cardprinteddate] [DATETIME] NULL,
[processedtime] [DATETIME] NULL,
[adminuserid] [VARCHAR](20) NULL,
[email] [VARCHAR](60) NULL,
[mobileno] [VARCHAR](20) NULL,
[city] [VARCHAR] (28),
[iqamaExpDate] [DATETIME] NULL,
[terminationReason] [VARCHAR] (1),
[LifeVestInd] [CHAR](1),
[LSBIndicator] [CHAR](1),
[UIDnumber] [VARCHAR] (20),
[VisaPlaceOfIssue] [VARCHAR] (50),
[eligdays] [DECIMAL](3, 0) NULL,
[certtype] [VARCHAR](50) NULL,
[BENIDTYPE] [VARCHAR](30) NULL,
[BENADDR1] [VARCHAR](30) NULL,
[BENADDR2] [VARCHAR](30) NULL,
[BENADDR3] [VARCHAR](30) NULL,
[BENADDR4] [VARCHAR](30) NULL,
[BENNATIONALITY] [CHAR](3) NULL,
[BENDOB] [DATETIME] NULL,
[BENFILE] [CHAR](1) NULL,
[FILETYPE] [CHAR](5) NULL,
[FILETYPEDESC] [VARCHAR](255) NULL,
[FILEFORMAT] [VARCHAR](255) NULL,
[FILESIZE] [INT] NULL,
[FILEPATH] [CHAR](1) NULL,
[FILETYPEFLAG] [CHAR](2) NULL,
[oldPolicyNo] [CHAR](10) NULL,
[oldSubOffCode] [CHAR](3) NULL,
[roleid] [CHAR](20) NULL,
[submitted by] [char] (200) NULL,
[oldbenplncd] [char] (3) NULL,
[SPONSORTYPE] [INT] NULL ,
[GROSSSALARYRANGE][CHAR](1) NULL,
[SALARYBASEDONCOMMISSION][CHAR](3) NULL,
[RESIDINGEMIRATE][CHAR](20) NULL,
[RESIDINGLOCATION][CHAR](20) NULL,
[WORKLOCATIONEMIRATE][CHAR](20) NULL,
[WORKLOCATION][CHAR](20) NULL,
[MEMBERINSURANCEINSIXMONTH][CHAR](50) NULL,
[VISASPONSORID][CHAR](20) NULL,
[SPONSORCONTACTNUMBER][CHAR](50) NULL,
[SPONSOREMAILID][CHAR](50) NULL,
)
/* End Temp table for Distributed out put*/
INSERT INTO #es_ediconsolidate
SELECT DISTINCT A.txtype,X.txdesc,txrefno,A.clntcode,A.polno,A.certno,A.depcode,deptype,namefirst,namelast,
namemid,A.inieffdt,A.status,A.chgeffdt,suboffcode,departcd,memidno,dob,sex,marital,occupation,empno,
empdt,salary,A.bankac,memnation,A.effdate,A.bankcode,A.salarymode,bankactype,bankaceffdate,bankacstatus,
firstcovdt,maxageexemptind,vipstatus,sponsoridno,passportno,nationalidno,bankname,branchname,branchaddress,
bankcurrency,swiftcode,servicedeskid,servicedeskdate,dmpindicator,salarychgeffdt,studentind, outcntyind,
PRODCODE =NULL,BENPLNCD =NULL,COVGCODE =NULL,PROPOSEDSA =NULL,PRDSTATUS =NULL,BENID = NULL,BENNAME =NULL,
BENRELAT =NULL,BENEFFDT =NULL,BENSHARE = NULL,REMARK =NULL,A.rcdsts,A.rcdusrid,A.rcddtstmp,txstatus,uploadusrid,
uploadtime,errorcode,errormsg, isprocessing,TR.SPONSORTYPE,TR.GROSSSALARYRANGE,TR.SALARYBASEDONCOMMISSION,
TR.RESIDINGEMIRATE,TR.RESIDINGLOCATION,TR.WORKLOCATIONEMIRATE,TR.WORKLOCATION,TR.MEMBERINSURANCEINSIXMONTH,
TR.VISASPONSORID,TR.SPONSORCONTACTNUMBER,TR.SPONSOREMAILID,
FROM tmemtrans A (NOLOCK)
INNER JOIN es_txtypes X (NOLOCK)
ON A.txtype = X.txtype
INNER JOIN tpolicy P (NOLOCK)
ON A.polno = P.polno
INNER JOIN tpolpdt TP (nolock)
ON A.polno = tp.polno
--INNER JOIN tpolpdtcom tcom (nolock)
-- ON tp.polno = tcom.polno and tp.prodcode = tcom.prodcode and tp.effdate = tcom.effdate and tcom.prducode in (select es_usercode.code from es_usercode where es_usercode.userid= a.UPLOADUSRID union select es_usercode.code from es_usercode, es_userrole where es_usercode.userid=es_userrole.supervisorid and es_userrole.userid=a.UPLOADUSRID)
left JOIN tclient C (nolock)
ON --A.profilecode = c.clntcode
--AND
P.clntcode = c.clntcode
--Here i am including the join ----
JOIN TMEMBERREGULATORYINFO TR (nolock)
ON TR.CLNTCODE = A.CLNTCODE
AND TR.CERTNO = A.CERTNO
AND TR.DEPCODE = A.DEPCODE
INNER JOIN @PolNosCanAccess polnos on polnos.polno= A.polno
添加了我的完整选择语句
SELECT DISTINCT A.txtype,X.txdesc, txrefno, A.clntcode,A.polno,certno,DEPCODE=NULL,DEPTYPE=NULL,
NAMEFIRST=NULL,NAMELAST=NULL,NAMEMID=NULL,INIEFFDT=NULL,STATUS=NULL,CHGEFFDT=NULL,SUBOFFCODE=NULL,
DEPARTCD=NULL,MEMIDNO=NULL,DOB=NULL,SEX=NULL,MARITAL=NULL,OCCUPATION=NULL,EMPNO=NULL,EMPDT=NULL,
SALARY=NULL,BANKAC=NULL,MEMNATION=NULL,EFFDATE=NULL,BANKCODE=NULL,SALARYMODE=NULL,BANKACTYPE=NULL,
BANKACEFFDATE=NULL,BANKACSTATUS=NULL,FIRSTCOVDT=NULL,MAXAGEEXEMPTIND=NULL,VIPSTATUS=NULL,
SPONSORIDNO=NULL,PASSPORTNO=NULL,NATIONALIDNO=NULL,BANKNAME=NULL,BRANCHNAME=NULL,BRANCHADDRESS=NULL,
BANKCURRENCY=NULL,SWIFTCODE=NULL,SERVICEDESKID=NULL,SERVICEDESKDATE=NULL,DMPINDICATOR=NULL,
SALARYCHGEFFDT=NULL,STUDENTIND=NULL,OUTCNTYIND=NULL,PRODCODE =NULL,BENPLNCD =NULL,COVGCODE =NULL,
PROPOSEDSA =NULL,PRDSTATUS =NULL,benid,benname,benrelat,beneffdt,benshare,remark,A.rcdsts,
A.rcdusrid,A.rcddtstmp,txstatus,uploadusrid,uploadtime,errorcode,errormsg,isprocessing,TR.SPONSORTYPE,TR.GROSSSALARYRANGE,TR.SALARYBASEDONCOMMISSION,
TR.RESIDINGEMIRATE,TR.RESIDINGLOCATION,TR.WORKLOCATIONEMIRATE,TR.WORKLOCATION,TR.MEMBERINSURANCEINSIXMONTH,
TR.VISASPONSORID,TR.SPONSORCONTACTNUMBER,TR.SPONSOREMAILID,
case when A.roleid = 'agent' or A.roleid = 'broker' or A.roleid = 'brokeradmin' or A.roleid = 'admin' then null else
case when A.roleid= 'policyholder'
then P.poldesc
else c.clntname
end
end as 'PARENTCLIENT',
'' as 'AGENTNAME',
'packagecode' = (select PackageDesc from dbo.TPackageType (NOLOCK) where packagecode = P.packagecode),P.province,'' as 'CARDPRINTEDDATE',processedtime,
adminuserid,EMAIL=NULL,MOBILENO=NULL,city=NULL,iqamaExpDate=NULL,terminationReason=NULL,LifeVestInd=NULL,LSBIndicator=NULL,UIDnumber=NULL,VisaPlaceOfIssue=NULL,ELIGDAYS=NULL,CERTTYPE=NULL,BENIDTYPE,BENADDR1,BENADDR2,BENADDR3,BENADDR4,BENNATIONALITY,BENDOB,CASE WHEN BENFILE IS NULL THEN 'N' ELSE 'Y' END AS 'BENFILE',FILETYPE=NULL,FILETYPEDESC=NULL,FILEFORMAT=NULL,FILESIZE=NULL,FILEPATH=NULL,FILETYPEFLAG=NULL,oldPolicyNo=NULL,oldSubOffCode=NULL,A.roleid ,
case a.roleid when 'brokeradmin' then (select top 1 tproducer.prduname from tproducer (NOLOCK), es_usercode (NOLOCK) where es_usercode.userid= a.UPLOADUSRID and es_usercode.code=tproducer.prducode )
when 'agencymanager' then (select tagency.agyname from tagency (NOLOCK), es_usercode (NOLOCK) where es_usercode.userid=a.UPLOADUSRID and substring(es_usercode.code, 1, 3) = tagency.agycode )
when 'unitmanager' then ( select top 1 tproducer.prduname from tproducer (NOLOCK), es_usercode (NOLOCK) where es_usercode.userid=a.UPLOADUSRID and es_usercode.code=tproducer.prducode)
when 'policyholderadmin' then (select top 1 tclient.clntname from tclient (NOLOCK), es_usercode (NOLOCK) where es_usercode.userid=a.UPLOADUSRID and es_usercode.code=tclient.clntcode)
when 'broker' then (select top 1 tproducer.prduname from tproducer (NOLOCK), es_usercode (NOLOCK), es_userrole (NOLOCK) where es_usercode.userid=es_userrole.supervisorid and es_userrole.userid=a.UPLOADUSRID and es_usercode.code=tproducer.prducode)
when 'agent' then (select top 1 tproducer.prduname from tproducer (NOLOCK), es_usercode where es_usercode.userid=a.UPLOADUSRID and es_usercode.code=tproducer.prducode)
when 'policyholder' then( select tpolicy.poldesc from tpolicy (NOLOCK) where tpolicy.polno =a.polno)
when 'member' then (select im.namefirst + ' ' + im.namelast from tmember im (NOLOCK) where im.certno=a.certno and im.clntcode=a.clntcode)
end 'submitted by',oldbenplncd=NULL
FROM tbenftrans A (NOLOCK)
INNER JOIN es_txtypes X (NOLOCK)
ON A.txtype = X.txtype
INNER JOIN tpolicy P (NOLOCK)
ON A.polno = P.polno
INNER JOIN tpolpdt TP(nolock)
ON A.polno = TP.polno
--INNER JOIN tpolpdtcom tcom (nolock)
--ON tp.polno = tcom.polno and tp.prodcode = tcom.prodcode and tp.effdate = tcom.effdate and tcom.prducode in (select es_usercode.code from es_usercode where es_usercode.userid= a.UPLOADUSRID union select es_usercode.code from es_usercode, es_userrole where es_usercode.userid=es_userrole.supervisorid and es_userrole.userid=a.UPLOADUSRID)
left JOIN tclient C (nolock)
ON P.clntcode = c.clntcode
但我收到了错误
Msg 4104,Level 16,State 1,Procedure ES_CONSOLIDATELIST_ADMIN_MEMBER,Line 360
无法绑定多部分标识符“TR.SPONSORTYPE”。
这是我的TMEMBERREGULATORYINFO
表架构
SELECT TOP 1000
[CLNTCODE]
,[CERTNO]
,[DEPCODE]
,[SPONSORTYPE]
,[GROSSSALARYRANGE]
,[SALARYBASEDONCOMMISSION]
,[RESIDINGEMIRATE]
,[RESIDINGLOCATION]
,[WORKLOCATIONEMIRATE]
,[WORKLOCATION]
,[MEMBERINSURANCEINSIXMONTH]
,[VISASPONSORID]
,[SPONSORCONTACTNUMBER]
,[SPONSOREMAILID]
FROM
[eService_EP].[dbo].[TMEMBERREGULATORYINFO]
有人请帮忙
答案 0 :(得分:0)
这应该有效!
The multi-part identifier "TR.SPONSORTYPE" could not be bound.
此错误是SQL向您显示他现在不是TR.SPONSORTYPE
的意思(他找不到表和列)的方式。这可能是由于某些因素最有可能存在类型,但也可能是数据库。如果下面的查询不起作用,则意味着您没有提供enought信息,因此我们可以为您提供解决方案。
SELECT DISTINCT A.txtype,
X.txdesc,
txrefno,
A.clntcode,
A.polno,
certno,
DEPCODE=NULL,
DEPTYPE=NULL,
NAMEFIRST=NULL,
NAMELAST=NULL,
NAMEMID=NULL,
INIEFFDT=NULL,
STATUS=NULL,
CHGEFFDT=NULL,
SUBOFFCODE=NULL,
DEPARTCD=NULL,
MEMIDNO=NULL,
DOB=NULL,
SEX=NULL,
MARITAL=NULL,
OCCUPATION=NULL,
EMPNO=NULL,
EMPDT=NULL,
SALARY=NULL,
BANKAC=NULL,
MEMNATION=NULL,
EFFDATE=NULL,
BANKCODE=NULL,
SALARYMODE=NULL,
BANKACTYPE=NULL,
BANKACEFFDATE=NULL,
BANKACSTATUS=NULL,
FIRSTCOVDT=NULL,
MAXAGEEXEMPTIND=NULL,
VIPSTATUS=NULL,
SPONSORIDNO=NULL,
PASSPORTNO=NULL,
NATIONALIDNO=NULL,
BANKNAME=NULL,
BRANCHNAME=NULL,
BRANCHADDRESS=NULL,
BANKCURRENCY=NULL,
SWIFTCODE=NULL,
SERVICEDESKID=NULL,
SERVICEDESKDATE=NULL,
DMPINDICATOR=NULL,
SALARYCHGEFFDT=NULL,
STUDENTIND=NULL,
OUTCNTYIND=NULL,
PRODCODE =NULL,
BENPLNCD =NULL,
COVGCODE =NULL,
PROPOSEDSA =NULL,
PRDSTATUS =NULL,
benid,
benname,
benrelat,
beneffdt,
benshare,
remark,
A.rcdsts,
A.rcdusrid,
A.rcddtstmp,
txstatus,
uploadusrid,
uploadtime,
errorcode,
errormsg,
isprocessing,
tr.sponsortype,
tr.grosssalaryrange,
tr.salarybasedoncommission,
tr.residingemirate,
tr.residinglocation,
tr.worklocationemirate,
tr.worklocation,
tr.memberinsuranceinsixmonth,
tr.visasponsorid,
tr.sponsorcontactnumber,
tr.sponsoremailid,
CASE
WHEN A.roleid = 'agent'
OR A.roleid = 'broker'
OR A.roleid = 'brokeradmin'
OR A.roleid = 'admin' THEN NULL
ELSE
CASE
WHEN A.roleid = 'policyholder' THEN P.poldesc
ELSE c.clntname
END
END AS 'PARENTCLIENT',
'' AS 'AGENTNAME',
'packagecode' = (SELECT packagedesc
FROM dbo.tpackagetype (nolock)
WHERE packagecode = P.packagecode),
P.province,
'' AS 'CARDPRINTEDDATE',
processedtime,
adminuserid,
EMAIL=NULL,
MOBILENO=NULL,
city=NULL,
iqamaExpDate=NULL,
terminationReason=NULL,
LifeVestInd=NULL,
LSBIndicator=NULL,
UIDnumber=NULL,
VisaPlaceOfIssue=NULL,
ELIGDAYS=NULL,
CERTTYPE=NULL,
benidtype,
benaddr1,
benaddr2,
benaddr3,
benaddr4,
bennationality,
bendob,
CASE
WHEN benfile IS NULL THEN 'N'
ELSE 'Y'
END AS 'BENFILE',
FILETYPE=NULL,
FILETYPEDESC=NULL,
FILEFORMAT=NULL,
FILESIZE=NULL,
FILEPATH=NULL,
FILETYPEFLAG=NULL,
oldPolicyNo=NULL,
oldSubOffCode=NULL,
A.roleid,
CASE a.roleid
WHEN 'brokeradmin' THEN (SELECT TOP 1 tproducer.prduname
FROM tproducer (nolock),
es_usercode (nolock)
WHERE
es_usercode.userid = a.uploadusrid
AND es_usercode.code = tproducer.prducode)
WHEN 'agencymanager' THEN (SELECT tagency.agyname
FROM tagency (nolock),
es_usercode (nolock)
WHERE
es_usercode.userid = a.uploadusrid
AND Substring(es_usercode.code, 1, 3) =
tagency.agycode)
WHEN 'unitmanager' THEN (SELECT TOP 1 tproducer.prduname
FROM tproducer (nolock),
es_usercode (nolock)
WHERE
es_usercode.userid = a.uploadusrid
AND es_usercode.code = tproducer.prducode)
WHEN 'policyholderadmin' THEN (SELECT TOP 1 tclient.clntname
FROM tclient (nolock),
es_usercode (nolock)
WHERE
es_usercode.userid = a.uploadusrid
AND es_usercode.code = tclient.clntcode)
WHEN 'broker' THEN (SELECT TOP 1 tproducer.prduname
FROM tproducer (nolock),
es_usercode (nolock),
es_userrole (nolock)
WHERE es_usercode.userid =
es_userrole.supervisorid
AND
es_userrole.userid = a.uploadusrid
AND es_usercode.code =
tproducer.prducode)
WHEN 'agent' THEN (SELECT TOP 1 tproducer.prduname
FROM tproducer (nolock),
es_usercode
WHERE es_usercode.userid = a.uploadusrid
AND es_usercode.code =
tproducer.prducode)
WHEN 'policyholder' THEN(SELECT tpolicy.poldesc
FROM tpolicy (nolock)
WHERE tpolicy.polno = a.polno)
WHEN 'member' THEN (SELECT im.namefirst + ' ' + im.namelast
FROM tmember im (nolock)
WHERE im.certno = a.certno
AND im.clntcode = a.clntcode)
END 'submitted by',
oldbenplncd=NULL
FROM tbenftrans A (nolock)
INNER JOIN es_txtypes X (nolock) ON A.txtype = X.txtype
INNER JOIN tpolicy P (nolock) ON A.polno = P.polno
INNER JOIN tpolpdt TP(nolock) ON A.polno = TP.polno
LEFT JOIN tclient C (nolock) ON P.clntcode = c.clntcode
JOIN eService_EP.dbo.TMEMBERREGULATORYINFO TR (nolock) ON TR.CLNTCODE = A.CLNTCODE
AND TR.CERTNO = A.CERTNO
AND TR.DEPCODE = A.DEPCODE
INNER JOIN @PolNosCanAccess polnos on polnos.polno= A.polno