如何为此构建动态 SQL?
我必须使用动态 SQL 创建过程并生成更新语句。
我有表
Col.TMap.T_Mp
ID M_Type ID_F SF1 SF2
1 Acc ACC_ID AC_ID NULL
1 STA STA_ID ST_ID NULL
1 CHa Cha_ID CH_ID NULL
ACC
ID AC_ID SV1 SV2 SO1 SO2
1 12 6 NULL = NULL
STA
ID STA_ID SV1 SV2 SO1 SO2
1 1 Open NULL = NULL
1 2 CLosed NULL = NULL
CHa
ID CHa_ID SV1 SV2 SO1 SO2
1 1 PH NULL = NULL
1 2 EM NULL = NULL
我需要使用上表中的 ACC_ID、STA_ID 和 CHA_ID 更新 Ms.AT.AT_CRAW_Dmtemp 表:
输出应该是:
UPDATE mt
SET ACC_ID = ac.ACC_ID
FROM Ms.AT.AT_CRAW t
INNER JOIN Acc ac ON t.AC_ID=SV1
AND ac.ID = 1
INNER JOIN Ms.AT.AT_CRAW_Dmtemp mt
ON mt.[SRID] = t.[RID]
UPDATE mt
SET STA_ID = ac.STA_ID
FROM Ms.AT.AT_CRAW t
INNER JOIN STA ac ON t.ST_ID=SV1
AND ac.ID = 1
INNER JOIN Ms.AT.AT_CRAW_Dmtemp mt
ON mt.[SRID] = t.[RID]
UPDATE mt
SET CHa_ID = ac.CHa_ID
FROM Ms.AT.AT_CRAW t
INNER JOIN CHa ac ON t.CH_ID=SV1
AND ac.ID = 1
INNER JOIN Ms.AT.AT_CRAW_Dmtemp mt
ON mt.[SRID] = t.[RID]
那么有人可以建议我如何执行此操作吗?
I have to create a Procedure with dynamic SQL and generate the Update Statements.
I have tables
Col.TMap.T_Mp
ID M_Type ID_F SF1 SF2
1 Acc ACC_ID AC_ID NULL
1 STA STA_ID ST_ID NULL
1 CHa Cha_ID CH_ID NULL
ACC
ID AC_ID SV1 SV2 SO1 SO2
1 12 6 NULL = NULL
STA
ID STA_ID SV1 SV2 SO1 SO2
1 1 Open NULL = NULL
1 2 CLosed NULL = NULL
CHa
ID CHa_ID SV1 SV2 SO1 SO2
1 1 PH NULL = NULL
1 2 EM NULL = NULL
I need to update Ms.AT.AT_CRAW_Dmtemp table with ACC_ID,STA_ID and CHA_ID from the above tables:
The out put should be:
UPDATE mt
SET ACC_ID = ac.ACC_ID
FROM Ms.AT.AT_CRAW t
INNER JOIN Acc ac ON t.AC_ID=SV1
AND ac.ID = 1
INNER JOIN Ms.AT.AT_CRAW_Dmtemp mt
ON mt.[SRID] = t.[RID]
UPDATE mt
SET STA_ID = ac.STA_ID
FROM Ms.AT.AT_CRAW t
INNER JOIN STA ac ON t.ST_ID=SV1
AND ac.ID = 1
INNER JOIN Ms.AT.AT_CRAW_Dmtemp mt
ON mt.[SRID] = t.[RID]
UPDATE mt
SET CHa_ID = ac.CHa_ID
FROM Ms.AT.AT_CRAW t
INNER JOIN CHa ac ON t.CH_ID=SV1
AND ac.ID = 1
INNER JOIN Ms.AT.AT_CRAW_Dmtemp mt
ON mt.[SRID] = t.[RID]
So can anyone suggest me on how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)