Click to See Complete Forum and Search --> : Stored procedure doubt(SQL SERVER)


shown_sunny
May 26th, 2004, 08:27 AM
dear friends,

Query1
======
***********************************************
SELECT @colvalue=column_name from information_schema.columns where ordinal_position=@cont and table_name=@tablename
***********************************************
Query2
======
***********************************************
select (select t.@colvalue from #trans_col t)
from information_schema.columns where ordinal_position=@cont and table_name=@tablename
****************************************************

1)These are the two queries within a procedure.

2)The solution I like to have is to get the value of a column_name.

3)The first query selects the corresponding name of a field .

4)What I wan't in the second query is to put this fieldname in the query and obtain the value of the corresponding field.

But this within the second query
***************************************
(select t.@colvalue from #trans_col t)
**************************************
doesn't work.

5)when i change the @ from colvalue ,the query returns only column name.

6)Is there a function in SQL SERVER to get the content of a fieldname


regards
shown_sunny

raghupathys
May 28th, 2004, 05:53 AM
You will have to use sp_executesql
rool your query into a string and then use
Exec sp_executesql @urvar

shown_sunny
May 31st, 2004, 07:49 AM
dear raghupathys

Thank u for u'r reply.

It was of very good help to me.Expecting for more help in the future too.

regards
shown_sunny