sql-server - 将表名和 where 条件动态传递到存储过程中,并将所有数据放入 #table 以供将来按摩
问题描述
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[myreport]
@lob_name VARCHAR(255),
@lob_id VARCHAR(255)
AS
BEGIN
DECLARE @Sql NVARCHAR(MAX);
SET @Sql ='SELECT TOP 100 l.id as lid,l.last_name as customer_name, l.phone_mobile into #maintable
FROM customer l with (nolock)
LEFT JOIN customer_cstm as c ON l.id = c.id_c
LEFT JOIN' + @lob_name +' AS m ON m.id=l.motor_id
LEFT JOIN report_retention p ON p.policy_no = m.policy_no
WHERE l.deleted = 0 AND (l.set_lob_type ='+ @lob_id+')
AND p.lob ='+ @lob_name+'
ORDER BY l.id ASC'
/*
Some massaging will here then will select #table
*/
SELECT * #maintable
我正在传递这些无法在#table 中复制的东西以进行按摩
- 我需要动态传递表格
- 在 where 条件下也动态传递参数
解决方案
推荐阅读
- javascript - 当类型:“DELETE”未通过时,Backbone destroy 方法正在触发 post 调用而不是 delete
- freeswitch - Freeswitch中是否有read的execute api?
- android - 调用 onItemLongClickListener 时,即使我在 onItemLongClick 中返回 true,也会调用 onItemClickListener
- vbscript - 单行输入 VBS 自动打字机
- kubernetes - 基于 pod 或部署的 GKE 账单明细
- java - 找出数字之间的阿姆斯壮数
- cloud-foundry - 没有一个 buildpack 检测到兼容的应用程序
- joomla - Joomla 文件未找到错误
- unity3d - 如何在 Unity 上使用 Google Text-To-Speech?
- ios - Cocopods Post_Install 脚本错误