【发布时间】:2020-03-11 09:07:46
【问题描述】:
我需要使用 JOIN 存储过程提取索赔人 ID 的所有策略列。
伪代码:select * from policies(tbl) whereparty.id = policy.policyNumber。
这是我目前所拥有的......
CREATE PROCEDURE [dbo].[usp_GetPolicyForClaimentByPolicyIdNumber]
(
@IdNumber varchar(255) = null
)
AS
BEGIN
SELECT *
FROM [BinderCurrent].[Policy]
LEFT JOIN [BinderCurrent].[Policy] ON ([BinderCurrent].[Parties].Id = [BinderCurrent].[PolicyRoles].PolicyId)
WHERE [BinderCurrent].[PolicyRoles].PolicyRoleTypeId = 40
AND (@IdNumber IS NULL OR [BinderCurrent].[Parties].IdNumber LIKE ''+@IdNumber+'%')
ORDER BY Id DESC
END
【问题讨论】:
-
“我需要”不是问题。你在这里问什么?为什么不是你已经不工作的东西?
-
您在
WHERE中引用了[BinderCurrent].[PolicyRoles],但在您的FROM中没有定义它。列的 3+ 部分命名也将被弃用和删除。建议您使用别名并使用这些别名来限定您的列。
标签: sql-server stored-procedures jointable