Solved

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

Posted on 2008-10-21
2
124 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now