January 7, 2009 at 5:47 pm
Hi,all
I have two tables ,Customer and Users ,which is related via FK.
Customer table contains Customers details like FullName,Address etc... and Users table contains login details like username and password.
My question is how to retrieve fullname from customer table when user logged in .
Any help appreciated...
Thanks in advance.
Ben
January 7, 2009 at 6:18 pm
You can use SUSER_SNAME
(ref:ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/11ec7d86-d429-4004-a436-da25df9f8761.htm)
to retrieve the FK from the users table and then using the FK in a join to retrieve the full name from your customer table.
Post the table definitions and some sample data following the article contained in my signature for more detailed assistance
January 10, 2009 at 10:51 pm
Suppose 'user_id' is the primary key in users table, and 'user_id' is the foreign key in the customers table,
a simple query will do the task for you
SELECT cust.full_name
FROM users u
INNER JOIN customers cust
ON cust.user_id = u.user_id
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply