Solved

Best Practice SQL. Is it possible to make this a view?

Posted on 2008-10-21
2
129 Views
Last Modified: 2012-05-05
I might be totally off here but I'm trying to avoid pointing to a specific row in the AccountGroup table. I want to be able to change the names of the groups but the Account Numbers has built in meanings according to standard chart of accounts in Europe.

AccountGroup contains AccountGroupNos like:
No: 1
Descr: 'Assets'
No: 11
Descr: 'My Machinery Assets of type 1'

Account contains the accountnos:

No: 1110
Descr: My Machine type 1
No: 1111
Desc: My Machine type 2

Now, is this good practice or should I in fact store the AccountGroupID in the Account based on the formula below each time I add an Account? Or if this is OK, is it possible to do the query without the #temp-table so I can put the code in a view?

I don't know if it makes a difference but the database is located in a .MDF SQL Express file and will run localy on the end users computer.

Tanks in advance!

/Tomas


SELECT a.AccountID, a.Accountno, a.AccountDescription, g.AccountGroupDescription 
INTO #TEMP
FROM Account a, AccountGroup g
WHERE left(a.accountno,2) = g.AccountGroupNo
SELECT AccountID, AccountNo, AccountDescription, a.AccountGroupDescription, g.AccountGroupDescription as MainAccountGroup
FROM #temp a, AccountGroup g
WHERE left(a.accountno,1) = g.AccountGroupNo
ORDER BY AccountNo

Open in new window

0
Comment
Question by:ekenman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:ekenman
ID: 22765965
OK, I managed to get the question a little bit more accurate. The question remaining is if it is OK to do this? Is it good practice?
SELECT     MG.AccountGroupNo as MainGroupNo, MG.AccountGroupDescription as MainAccountGroupDescription, G.AccountGroupNo, G.AccountGroupDescription, Account.AccountNo, Account.AccountDescription
FROM         Account INNER JOIN
                      AccountGroup as G ON LEFT(Account.AccountNo, 2) = G.AccountGroupNo INNER JOIN
					  AccountGroup as MG ON LEFT(Account.AccountNo,1) = MG.AccountGroupNo 

Open in new window

0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 250 total points
ID: 22772424
Based upon your query above in http:#22765965, the AccountGroupNo should be in the Account table.  It also seems, since you have two joins to accountgroup, that an account is part of two groups.  once based upon the first and once based upon the second.  Perhaps this is a good candidate for group and subgroup.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question