私のストアドプロシージャは次のとおりです。
CREATE PROCEDURE [dbo].[USP_GET_MBR_DWN_DTL] (@MBR_ID VARCHAR(50), @LEG_POS CHAR)
AS BEGIN
WITH CTE(MBR_ID, MBR_LEG_POS, MBR_NM, MBR_JOIN_TT, LVL, MBR_UPR_ID, MBR_SPR_ID) AS
(
SELECT
CAST(MBR_ID AS VARCHAR(100)) as MBR_ID,
MBR_LEG_POS, MBR_NM, MBR_JOIN_TT,
CAST(MBR_UPR_ID AS VARCHAR(100)) as MBR_UPR_ID,
CAST(MBR_SPR_ID AS VARCHAR(100)) as MBR_SPR_ID,
LVL=0
FROM MBR_MST
WHERE MBR_UPR_ID=@MBR_ID and MBR_LEG_POS=@LEG_POS
UNION ALL
SELECT
CAST(M.MBR_ID AS VARCHAR(100)) as MBR_ID,
M.MBR_LEG_POS,M.MBR_NM,M.MBR_JOIN_TT,
CAST(M.MBR_UPR_ID AS VARCHAR(100)) as MBR_UPR_ID,
CAST(M.MBR_SPR_ID AS VARCHAR(100)) as MBR_SPR_ID,
LVL+1
FROM MBR_MST M
JOIN CTE F ON CAST(M.MBR_UPR_ID AS VARCHAR(100))=CAST(F.MBR_ID AS VARCHAR(100))
)
SELECT * FROM CTE ORDER BY LVL, MBR_JOIN_TT OPTION (MAXRECURSION 0)
END
しかし、私が走るとき
USP_GET_MBR_DWN_DTL 'Flife1', 'A'
それはエラーを示しています
メッセージ 245、レベル 16、状態 1、手順 USP_GET_MBR_DWN_DTL、行 5
varchar 値 'Flife1' をデータ型 int に変換するときに変換に失敗しました。