gearbolt Posted July 21, 2003 Posted July 21, 2003 This procedure was created by SQL Server and I was wondering was the code generated correct. I am not sure if the Inner Joins are correct. I am trying to select all of the accounts from the table called "tbl_Accounts" and instead of returning the ID number of each foreign key I want to return the actual data. For example 1 = Savings 2 = Checking 3 = 401K I have included the sp and the tables below. Thanks Select dbo.tbl_Accounts.Account_ID_Number, dbo.tbl_Accounts.char_Account_Name, dbo.tbl_Accounts.date_Account_Open_Date, dbo.tbl_Accounts.date_Account_Closed_Date, dbo.tbl_Accounts.int_Account_Balance, dbo.tbl_Accounts.int_Account_Balance, dbo.tbl_Account_Types.char_Account_Types, dbo.tbl_Account_Status.char_Current_Status FROM dbo.tbl_Accounts INNER JOIN dbo.tbl_Account_Status ON dbo.tbl_Accounts.Account_Status_ID_Number = dbo.tbl_Account_Status.Account_Status_ID_Number INNER JOIN dbo.tbl_Account_Types ON dbo.tbl_Accounts.Account_Types_ID_Number = dbo.tbl_Account_Types.Account_Types_ID_Number Here are the tables in the database tbl_Accounts ---------------- Account_ID_Number char_Account_Name date_Account_Open_Date date_Account_Closed_Date int_Account_Balance char_Account_Issuer Account_Types_ID_Number [fk] Account_Status_ID_Number [fk] tbl_Account_Types ----------------------- char_Account_Types Account_Types_ID_Number tbl_Account_Status ------------------------- Account_Status_ID_Number char_Current_Status Quote
JABE Posted July 21, 2003 Posted July 21, 2003 It seems so especially since it was generated by SQL Server as you mentioned. The easiest way to verify is to run this procedure in Query Analyzer. Quote
*Experts* Nerseus Posted July 21, 2003 *Experts* Posted July 21, 2003 It seems work fine assuming you will always have an account type and account status per Account record. If not, you may need outer joins. Also, you may or may not need all the fields returned by the SELECT - I'd pick and choose only those fields you need as having extra fields means more network traffic (and temp DB space, etc.). The big test, as JABE pointed out, is does it work when you run it? -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
gearbolt Posted July 22, 2003 Author Posted July 22, 2003 The SP those work but I questioned the results becasue SQL generated another SP the used cross joins and they were not neccsary. My SQL is not that good but I know you do not need cross joins when selecting two fields in the same table. Thanks for the help as always. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.