SQL Server 2008 – How to Create a Stored Procedure with Columns from Three Different Tables

sql-server-2008stored-procedures

I'm a fresher and I would like to get some suggestions on how to create a stored procedure in which I have to select columns from three different tables. 2 columns customername and customercode from first table, loan type from second table and account number, status from 3rd table.

Best Answer

SELECT 
    C.customername 
    ,C.customercode
    ,L.[loan type] 
    ,S.[account number]
    ,S.status
FROM
    [first table] AS C
    INNER JOIN [second table] AS L
    ON C.customercode = L.customercode
    INNER JOIN  [3rd table] AS S
    ON S.customercode = C.customercode

This is only as a guidance; it is better to post some sample data and definitions.