Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
my stored procedure errors :invalid coloums but sp completed successfully but parameters are errors,my codes are here
SQL
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
Posted
Updated 8-Dec-11 20:55pm
v2

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

SQL
exec ei_sp_available ei_country,'CountryName'
 
Share this answer
 
Comments
Vasim889 9-Dec-11 20:57pm    
I am also try it?but invalid countryname
Mehdi Gholam 10-Dec-11 1:08am    
The table ei_country must contain the column CountryName.
SQL
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
 
Share this answer
 
Hi, use below SP

SQL
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
:)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900