34,575
社区成员
发帖
与我相关
我的任务
分享
CREATE PROCEDURE [dbo].[Up_Pretreatment_registerNo]
@status nvarchar(50) output,
@客户ID_OutPut nvarchar(50) output,
@strSQL nvarchar(max)
AS
declare @sql nvarchar(max)
set @sql='select t1.工商注册号 as 导入工商注册号,
t1.联系电话 as 导入电话,
t1.客户名称 as 导入客户名称,
t1.联系人 as 导入联系人,
t1.备注 as 导入备注,
t2.工商注册号 as 库内工商注册号,
t2.客户ID as 库内客户ID,
t3.ph as 库内电话,
case when t2.客户ID is not null and t3.ph is not null then 0 when t2.客户ID is not null and t3.ph is null then 1
when t2.客户ID is null then 2 end as 状态
from ('+@strSQL+'
) t1
left join pre_database t2 on t1.工商注册号=t2.工商注册号
left join pre_database_phone t3 on t2.客户ID=t3.客户ID and t3.ph=t1.联系电话
group by t1.工商注册号,t1.联系电话,t2.工商注册号,t3.ph,t2.客户ID,t1.客户名称,t1.联系人,t1.备注,
case when t2.客户ID is not null and t3.ph is not null then 0 when t2.客户ID is not null and t3.ph is null then 1
when t2.客户ID is null then 2 end'
exec(@sql)
CREATE TABLE #TMP(//列定义)
INSERT INTO #TMP EXEC(@strSQL)
②、后面的查询使用#TMP