sql存储过程错误 [英] sql stored procedure Error

查看:69
本文介绍了sql存储过程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的存储过程错误:无效的列,但sp成功完成,但参数错误,我的代码在这里

my stored procedure errors :invalid coloums but sp completed successfully but parameters are errors,my codes are here

create PROCEDURE   ei_sp_available
	
	@Table varchar(100),
@Type varchar(100) 
AS
BEGIN
	
	SET NOCOUNT ON;

   
Execute
('select count(*) from '+@Table+' where [Name]= '+@Type+'')
END
exec ei_sp_available ei_country,CountryName
error:invalid CountryName

推荐答案

CountryName被用作变量,因此invalid错误,请使用以下内容:

CountryName is being used as a variable hence the invalid error, use the following :

exec ei_sp_available ei_country,'CountryName'


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
create PROCEDURE [dbo].[ei_sp_available] 
	-- Add the parameters for the stored procedure here
@Table varchar(100)=null,
@FieldName varchar(100)=null,
@FieldValue varchar(100)=null
AS
BEGIN
-- exec ei_sp_available 'ei_country','country' ,'India'
	
Execute
(

'select count(*) from '+ @Table +' where ' + @FieldName +' ='''+ @FieldValue +''''

)
END


您好,请在SP下方使用

Hi, use below SP

create PROCEDURE [dbo].[ei_sp_available] 
	-- Add the parameters for the stored procedure here
@TableName varchar(100),
@FieldName varchar(100),
@FieldValue varchar(100)
AS
BEGIN	
Execute
('select count(*) from '+ @TableName +' where ' + @FieldName +' ='''+ @FieldValue +'''')
END

:)


这篇关于sql存储过程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆