selecting query at run time

  • Hi

    i am a newbie my problem is in my db there are 10 registered usernames wen one of the user logged in to my site i want to display his information i am using ms sql db pls tell me how to give a select query at run time wen a user logged in for this with examples

  • Hi

    Could you provide some more detail such as what information are you wanting to return about the user & what application are you using e.g are you using reporting services.

  • Thanx for reply yes i am working on reports in my db all the users have similar fields like state,city,country i want to retrieve only logged user report wen he entered in to his account so i want to give a select query dynamically at run time pls give suggestion with example.

    Thaqnx

  • Hi

    Within Reporting Services there is a Global variable called [UserId].

    You will need to create a report parameter and assign its default value to use the [UserId] global variable. You can then reference this report parameter in the WHERE clause of your dataset.

    I'm assuming you have a table that has your user information stored by userid;

  • You can also use the below to get user name in sql queries.

    SELECT SYSTEM_USER

  • Hi,

    If you are using a web site, then it would be a better idea to use the HTTP_REFERER to read the user id and display it on the page. You can also use this to log user activity in the database.

    If you want to find out the user in the database, use user_id() or user_name() from the sql server database.

    🙂

  • You could use your ASP/PHP form(POST/GET) variable to show the user. Take care with the SQL injections.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply