I have a function which takes two parameter type and value. According to the type it will search the correspon开发者_如何学Goding table whether the value exist or not and return a boolean value. Now I have created a table with the type as columns. I want to pass the column name and its corresponding values to be passed to the function.
For example
manager employee
======= =========
leo john
lia joesph
this is the table with column name manager and employee and their corresponding values. I need to get like
function validate(columnname1,columnvaue1),
function validate(columnname1,columnvaue2),
function validate(columnname2,columnvaue1),
function validate(columnname2,columnvaue2)
Can you please suggest me a solution....
My SQL is incredibly rusty but does this help? (I even tested it :)
CREATE PROCEDURE [dbo].[ValidateValue]
@columnname nchar(10),
@columnvalue nchar(10),
@tablename nchar(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
DECLARE @SQL varchar(200)
SELECT @SQL = 'SELECT COUNT(*) FROM ' +
@tablename + ' WHERE ' +
@columnname + ' = ' + QUOTENAME(@columnvalue,CHAR(39))
EXEC (@SQL)
END
精彩评论