Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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.
  • *Experts*
Posted

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

"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
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...