Table name as parameter
-
Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V
-
Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V
-
Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V
You can use dynamic sql to do that. For instance, if you have a procedure that gets column_in as column parameter and table_in as table parameter, then you can write something like this: (Oracle SQL, haven't tested elsewhere)
OPEN ref_cur1 FOR 'SELECT ' || column_in || ' FROM ' || table_in;
I think if you are using SQL SERVER then you should just omit the OPEN...FOR part. -
Hi, Can I pass table name as a parameter to an stored procedure. Please is there any round the way to do this. Regards, Chakravarthy.V
Hope it'll help CREATE PROCEDURE [DBO].[GetFieldByID] (@FieldName varchar(50), @TableName varchar(50), @IDVal int) AS declare @IDField varchar(50) set @IDField = @TableName + 'ID' exec('select ' + @FieldName + ' from ' + @TableName + ' where ' + @IDField + ' = ' + @IDVal) GO UTSAV
-
Hope it'll help CREATE PROCEDURE [DBO].[GetFieldByID] (@FieldName varchar(50), @TableName varchar(50), @IDVal int) AS declare @IDField varchar(50) set @IDField = @TableName + 'ID' exec('select ' + @FieldName + ' from ' + @TableName + ' where ' + @IDField + ' = ' + @IDVal) GO UTSAV
Hi, It is working fine, thank you very much. Regards, Chakravarthy.v
-
Hope it'll help CREATE PROCEDURE [DBO].[GetFieldByID] (@FieldName varchar(50), @TableName varchar(50), @IDVal int) AS declare @IDField varchar(50) set @IDField = @TableName + 'ID' exec('select ' + @FieldName + ' from ' + @TableName + ' where ' + @IDField + ' = ' + @IDVal) GO UTSAV
Hi, I tested it but it is causing some problems, can you please verify this because this query is imp for me. Initially I tested this code only by passing the code then it worked fine. Regards KLAYAN
-
Hi, I tested it but it is causing some problems, can you please verify this because this query is imp for me. Initially I tested this code only by passing the code then it worked fine. Regards KLAYAN
wELL THIS CODE IS DAMN TESTED, I GUESS U R MISSING WRONG DATATYPE VALUE ooops, sorry 4 caps lock on, hope u'd not mind ;) UTSAV