SQL Server 2005 语法错误

发布于 2024-09-11 23:34:23 字数 1132 浏览 6 评论 0原文

这是 SQL:

CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)

INSERT INTO dbo.TmpFeesToRules1(Name, LookupId)
SELECT DISTINCT Name, 0 FROM Lending.Fee
UNION SELECT DISTINCT Name, 0 FROM Lending.ApplicationFee

INSERT INTO dbo.tblLookup (LookupType, LookupCode, LookupDesc, EditFlag, DeletedFlag, DefaultFlag)
SELECT 'FEE_CODE', Name,  Name, 0, 0, 0
FROM dbo.TmpFeesToRules1

UPDATE dbo.TmpFeesToRules1
SET
    LookupId = L.LookupID
FROM
    dbo.tblLookup L
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = L.LookupDesc
WHERE
    L.LookupType = 'FEE_CODE'

CREATE TABLE dbo.TmpFeesToRules2(FeeId int, Name varchar)

INSERT INTO dbo.TmpFeesToRules2(FeeId, Name)
SELECT FeeId, Name FROM Lending.ApplicationFee

GO

UPDATE Lending.ApplicationFee 
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM dbo.TmpFeesToRules2 TT
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId

DROP TABLE dbo.TmpFeesToRules1
DROP TABLE dbo.TmpFeesToRules2

这是错误:

对象名称“dbo.TmpFeesToRules2”无效。
执行失败,返回码:1

有什么想法吗?

Here is the SQL:

CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)

INSERT INTO dbo.TmpFeesToRules1(Name, LookupId)
SELECT DISTINCT Name, 0 FROM Lending.Fee
UNION SELECT DISTINCT Name, 0 FROM Lending.ApplicationFee

INSERT INTO dbo.tblLookup (LookupType, LookupCode, LookupDesc, EditFlag, DeletedFlag, DefaultFlag)
SELECT 'FEE_CODE', Name,  Name, 0, 0, 0
FROM dbo.TmpFeesToRules1

UPDATE dbo.TmpFeesToRules1
SET
    LookupId = L.LookupID
FROM
    dbo.tblLookup L
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = L.LookupDesc
WHERE
    L.LookupType = 'FEE_CODE'

CREATE TABLE dbo.TmpFeesToRules2(FeeId int, Name varchar)

INSERT INTO dbo.TmpFeesToRules2(FeeId, Name)
SELECT FeeId, Name FROM Lending.ApplicationFee

GO

UPDATE Lending.ApplicationFee 
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM dbo.TmpFeesToRules2 TT
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId

DROP TABLE dbo.TmpFeesToRules1
DROP TABLE dbo.TmpFeesToRules2

Here is the error:

Invalid object name 'dbo.TmpFeesToRules2'.
Execute failed, return code: 1

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

も让我眼熟你 2024-09-18 23:34:23

Go或分号无关,

您正在更新Lending.ApplicationFee,但它没有出现在FROM子句中。

UPDATE Lending.ApplicationFee 
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM dbo.TmpFeesToRules2 TT
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId

我想这应该是这样的

UPDATE Lending.ApplicationFee 
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM Lending.ApplicationFee join dbo.TmpFeesToRules2 TT ON <Some Condition>
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId

Nothing to do with Go or semicolons,

You are updating Lending.ApplicationFee but it doesn't appear in the FROM clause.

UPDATE Lending.ApplicationFee 
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM dbo.TmpFeesToRules2 TT
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId

I guess this should be something like

UPDATE Lending.ApplicationFee 
SET Lending.ApplicationFee.FeeTypeId = T.LookupId
FROM Lending.ApplicationFee join dbo.TmpFeesToRules2 TT ON <Some Condition>
INNER JOIN dbo.TmpFeesToRules1 T ON T.Name = TT.Name
WHERE Lending.ApplicationFee.FeeId = TT.FeeId
☆獨立☆ 2024-09-18 23:34:23

而不是

CREATE TABLE dbo.TmpFeesToRules2(FeeId int, Name varchar)

INSERT INTO dbo.TmpFeesToRules2(FeeId, Name)
SELECT FeeId, Name FROM Lending.ApplicationFee

你可以这样做:

SELECT FeeId, Name 
INTO dbo.TmpFeesToRules2 
FROM Lending.ApplicationFee

这将一步创建并填充表

Instead of

CREATE TABLE dbo.TmpFeesToRules2(FeeId int, Name varchar)

INSERT INTO dbo.TmpFeesToRules2(FeeId, Name)
SELECT FeeId, Name FROM Lending.ApplicationFee

you could just do:

SELECT FeeId, Name 
INTO dbo.TmpFeesToRules2 
FROM Lending.ApplicationFee

That will create and populate the table in one step

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文