Is this Stored Procedure Correct

gearbolt

Member
Joined
Mar 16, 2003
Messages
14
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
 
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.
 
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 - Id 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
 
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.
 
Back
Top