views:

56

answers:

1

Hi all

I have a function which takes two parameter type and value. According to the type it will search the corresponding 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....

A: 

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
MikeAinOz