February 23, 2006 at 11:33 am
hi,
is any one help me in making the correct stored proc??
I want to pass column and table name in the query using the stored proc:
For example:
--------------
create proc USP_Generic @columns varchar(50), @tbl varchar(100)
As
select @columns from @tbl
Go
-------------
Please give me the correct script
Thanx
February 23, 2006 at 11:40 am
Why would you want to do this?
Look for Dynamic sql. But you shouldn't use it if you don't understand it.
February 23, 2006 at 11:42 am
You could do it. But I wouldnt recommend it.
You would need to use Dynamic SQL and use sp_ExecuteSQL to execute the string.
Something along these lines:
DECLARE @sql nvarchar(500)
SET @sql = 'SELECT ' + @columns +' FROM' + @tbl
sp_ExecuteSQL N'@sql
Check out books on line for sp_ExecuteSql and they have more info with sample code.
******************
Dinakar Nethi
Life is short. Enjoy it.
******************
February 24, 2006 at 12:03 pm
Thanx buddy, Its working..
I really love this ..
Thanx for prompt response..
Noman
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply