创建复杂的插入语句
因此,我一直在尝试为我正在制作的报告创建一个插入语句,该语句从其他几个表,列和串联的一些列中汲取了信息。
到目前为止,我已经有了这个,它将返回0行而没有错误。
INSERT INTO ClientNexusCleanseReport (PotentialMatchName,
EstablishmentType,
CorrectAllocationId,
PotentialAddress,
PotentialPostCode,
ClosureDate,
Company,
CompanyCode,
CRMName,
HowItWasAllocated,
CorrectClientNexusID,
LastTransactionDate,
HowItShouldBeAllocated,
AllocationIDType,
DataCategory,
OtherComments)
SELECT et.EstablishmentName,
et.[TypeOfEstablishment (name)],
et.URN,
CONCAT(et.street, ', ', et.locality, ', ', et.address3, ', ', et.Town, ', ', et.[county (name)]),
et.postCode,
et.CloseDate,
ca.company,
ca.code,
ca.ClientName,
CONCAT(ca.ClientKnownType, ' - ', cnm.ClientnexusSubType),
cnm.ClientNexusMasterID,
CONCAT(cp.year, cp.Month),
'Edubase',
'Edubase URN',
'1a 1c',
'Incorrect Name, Incorrect URN'
FROM edubasealldata et
INNER JOIN ClientNexusMaster cnm ON cnm.ClientNexusName = et.EstablishmentName
INNER JOIN ClientNexusCRMAccounts ca ON ca.ClientName = cnm.ClientNexusName
INNER JOIN ClientNexusCRMProduct cp ON cp.Code = ca.Code
WHERE ca.ClientName = ' Ark Schools T/a Ark Priory Primary Academy';
这个想法是在我必须清洁的每种情况下创建一排信息,即从数据库周围收集有关此情况的信息,操纵该信息(通过使用concat)并将其编译成一排,以告诉我该情况的问题以及正确的信息。
因此,我已经完成了,将插入物添加到语句中,然后添加了Select语句,然后加入表格,然后指定了我希望在Where语句中进行的特定情况。
问题是我在运行此操作时不会收到错误,但是它说(0行影响)。
,因此我不确定自己做错了什么。
更新
感谢您的所有建议和答复。 正如@Kendle所说,我想我弄清楚了我的出错,我的加入没有找到匹配的记录。
基本上,我正在清洁数据。
我的工作是找到混乱的记录(“方舟学校T/A Ark Priory初等学院”,并将其与正确的唱片“ Ark Priory初级学院”相匹配。 然后用正确的数据填充该记录以及原始问题是什么。
因此,我从表的3个,帐户表 e,产品表和 Master Table 中收集了错误的数据/业务数据,然后合并通过来自 edubase表的正确数据(我还在最后手动填写差距)。
因此,问题在于我没有任何东西可以将错误的数据直接链接到正确的数据。
我已经看着Stackoverflow。我可以使用交叉加入
在其中指定要获取不正确的数据其中ca.clientname ='ARK Schools T/A ARK Priory初级学院'
正确和正确的,我可以实现所需的结果。 data where et.EstabloumpryName ='ARK Priory初级学院'
?
还是我可以使用insert
语句,然后是更新
语句来产生我想要的结果?因此插入
... 其中ca.clientname ='ARK Schools T/A ARK PRIORY初级学院'
然后 update ... et.Est.eStabloublyName ='ARK Priory初级学院'
?
再次感谢您的所有帮助!
So I’ve been trying to create an Insert statement for a report I am making, that draws information from several other tables, Columns and concatenates some of the columns.
So far I have this and it returns 0 rows with no errors.
INSERT INTO ClientNexusCleanseReport (PotentialMatchName,
EstablishmentType,
CorrectAllocationId,
PotentialAddress,
PotentialPostCode,
ClosureDate,
Company,
CompanyCode,
CRMName,
HowItWasAllocated,
CorrectClientNexusID,
LastTransactionDate,
HowItShouldBeAllocated,
AllocationIDType,
DataCategory,
OtherComments)
SELECT et.EstablishmentName,
et.[TypeOfEstablishment (name)],
et.URN,
CONCAT(et.street, ', ', et.locality, ', ', et.address3, ', ', et.Town, ', ', et.[county (name)]),
et.postCode,
et.CloseDate,
ca.company,
ca.code,
ca.ClientName,
CONCAT(ca.ClientKnownType, ' - ', cnm.ClientnexusSubType),
cnm.ClientNexusMasterID,
CONCAT(cp.year, cp.Month),
'Edubase',
'Edubase URN',
'1a 1c',
'Incorrect Name, Incorrect URN'
FROM edubasealldata et
INNER JOIN ClientNexusMaster cnm ON cnm.ClientNexusName = et.EstablishmentName
INNER JOIN ClientNexusCRMAccounts ca ON ca.ClientName = cnm.ClientNexusName
INNER JOIN ClientNexusCRMProduct cp ON cp.Code = ca.Code
WHERE ca.ClientName = ' Ark Schools T/a Ark Priory Primary Academy';
The idea is to create a row of information on each Case I have to clean, i.e gather information on the Case from around the Database, manipulate that information (By using Concat) and compile it into a row that tells me the problem with that case as well as the correct information.
So I have gone through, added the INSERT Into statement, then added the SELECT statement then JOINED the Tables then specified the particular case I want this all to be about in a WHERE statement.
Problem is that I don't receive an error when I run this, but it says (0 rows affect).
So I am not entirely sure what I have done wrong.
UPDATE
Thank you for all the advice and responses.
I think I figured out where I was going wrong, as @Kendle said, my joins were not finding matching records.
Basically I am Data Cleaning.
My job is to find messy records (' Ark Schools T/a Ark Priory Primary Academy' and Match them to the correct record 'Ark Priory Primary Academy'.
Then populate that record with the correct data and what the original problem was.
So I gather the incorrect data/business data from 3 of the tables, the Account Table, Product Table and the Master Table and then merge that with the correct data from the Edubase Table (I also fill in the gaps manually at the very end).
So the problem is that I don't have anything to directly link the Incorrect Data to the correct Data.
I have looked up on StackOverflow. Could I achieve the desired outcome with a CROSS JOIN
where I specify to get in incorrect data WHERE ca.clientName = ' Ark Schools T/a Ark Priory Primary Academy'
and correct data WHERE et.establishmentname = 'Ark Priory Primary Academy'
?
Or could I use an INSERT
statement followed by an UPDATE
statement to produce result I want? SO INSERT
... WHERE ca.clientName = ' Ark Schools T/a Ark Priory Primary Academy'
then UPDATE
... WHERE et.establishmentname = 'Ark Priory Primary Academy'
?
Thank you again for all of the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论