本文介绍了如何在存储过程中传递tablename,列名和值作为参数。面临一些问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

USE [customcontrolsetting]
GO
/****** Object:  StoredProcedure [dbo].[sp_all_task]    Script Date: 10/10/2013 12:50:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_all_task] 

	@table_name nvarchar(max),
    @taction nvarchar(max),
    @tcolumn nvarchar(max),
    @tvalues nvarchar(max),
    @tconditions nvarchar(max)

	
AS
BEGIN
SET NOCOUNT ON;

DECLARE @cmd AS NVARCHAR(max)
 
if(@taction = 'insert')

SET @cmd='insert into '+@table_name+' ('+@tcolumn+') values('+@tvalues+') '
EXEC sp_all_task @cmd 

END







这是我的在商店程序中查询...





EXEC [sp_all_task] @ table_name ='AA',@ taction ='insert',@ tcolumn ='CC',@ tvalues ='DD',@ tconditions ='EE'



当我执行这个以下错误时发生



错误






this is my query in store procedure ...


EXEC [sp_all_task] @table_name='AA',@taction='insert', @tcolumn='CC',@tvalues='DD',@tconditions='EE'

when i execute this folowing error is occured

error

Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 201, Level 16, State 4, Procedure sp_all_task, Line 0
Procedure or function 'sp_all_task' expects parameter '@taction', which was not supplied.
Msg 217, Level 16, State 1, Procedure sp_all_task, Line 20
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

推荐答案


EXEC [sp_all_task] 'AA','insert','CC','DD','EE'

此外,只需编写

EXECUTE (@cmd)

而不是

EXEC sp_all_task @cmd


SET @cmd='insert into '+@table_name+' ('+@tcolumn+') values('+Char(39)+@tvalues+Char(39)+')'



只需写一下

And
Just write

EXEC @cmd

用于执行字符串。

这里Char(39)是ASCII值单引号。

for executing string.
Here Char(39) is ASCII value for single quote.


这篇关于如何在存储过程中传递tablename,列名和值作为参数。面临一些问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 05:27