C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

How to Pass column names dynamically to a query


Posted Date: 01 Dec 2007      Posted By: veeresh narasappa      Member Level: Bronze     Points: 2   Responses: 1



Hi all,

Here iam getting RoleId and iam storing it in a variable @str2.Now
i want to use this variable data as a column name in third query i.e
@str3.Please help me on this.


alter procedure LogProc
(
@UserId varchar(500),
@Password varchar(500)
)
as
Begin
declare @str1 varchar(500)
declare @str2 varchar(500)
declare @str3 varchar(500)
select @str1=AstId from UserTable where UserId=@UserId and Password = @Password;
select @str2=RoleID from AstProf where AstId =@str1 ;
select @str3=MenuId from MenuTable where @str2='y';
select @str3;
End


exec LogProc 'veeresh','veeresh'





Responses

Author: Mohammed Shadab    01 Dec 2007Member Level: BronzeRating: 2 out of 52 out of 5     Points: 2

hi use
Exec sp_executesql @sql

where @sql store whole query of yours



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Query to avoid repeated records
Previous : how to create database?
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use