473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question: Sample sets and how do I manage them

Hi everyone,

I have a table with a set of accounts in that contains one row for each
account for each time it has been audited. (this may not include every
account we deal with)

Each month I want to select, from a separate and full list of accounts
that i import to the database, a random selection of new accounts to be
audited this month. Hence, a row for each one needs to be added to the
original database and the most recent entry updated (if it has been
audited before).

I don't want to select an account for re-audit within 3 months (for
example) and the accounts have a category. I want the sample selection
to be variable for each category i.e. 12 account of type A, 25 accounts
of type B etc.

I'm currently doing this with query upon query upon query (about 16 at
the moment) and can't help thinking that there must be a more logical
way of doing this in code or maybe by using more effective queries...

I'm looking for advice on the approach i should take not really looking
for code samples but will take advice on that if it is provided.

Any good ideas out there?

Thanks,

Rob.

Nov 13 '05 #1
3 1540

"dkintheuk" <rm*******@firenet.uk.com> schreef in bericht news:11*********************@o13g2000cwo.googlegro ups.com...
Hi everyone,

I have a table with a set of accounts in that contains one row for each
account for each time it has been audited. (this may not include every
account we deal with)

Each month I want to select, from a separate and full list of accounts
that i import to the database, a random selection of new accounts to be
audited this month. Hence, a row for each one needs to be added to the
original database and the most recent entry updated (if it has been
audited before).

I don't want to select an account for re-audit within 3 months (for
example) and the accounts have a category. I want the sample selection
to be variable for each category i.e. 12 account of type A, 25 accounts
of type B etc.

I'm currently doing this with query upon query upon query (about 16 at
the moment) and can't help thinking that there must be a more logical
way of doing this in code or maybe by using more effective queries...

I'm looking for advice on the approach i should take not really looking
for code samples but will take advice on that if it is provided.

Any good ideas out there?

Thanks,

Rob.


Hi Rob,
If you need 16 query's for this, there is something wrong in your approch.
I think a UNION-query is what you need here.

I suppose you have a table called TblAccounts (AccountID-AccountType)
and a Table Called TblAudits (AccountID-AuditDate) (or a query with the last AuditDate for each Account)

3 months is ~ 100 days so something like:

SELECT TOP 12 TblAccounts.AccountID, TblAudits.AuditDate
FROM TblAccounts LEFT JOIN TblAudits ON TblAccounts.AccountID = TblAudits.AccountID
WHERE (((TblAudits.AuditDate) Is Null Or (TblAudits.AuditDate)>Date()-100) AND ((TblAccounts.AccountType)="A"))
UNION SELECT TOP 25 TblAccounts.AccountID, TblAudits.AuditDate
FROM TblAccounts LEFT JOIN TblAudits ON TblAccounts.AccountID = TblAudits.AccountID
WHERE (((TblAudits.AuditDate) Is Null Or (TblAudits.AuditDate)>Date()-100) AND ((TblAccounts.AccountType)="B"))
.......
UNION SELECT Top xx ........ where ...... AccountType) = "Z"))

will give you what you need.
You will have to adapt this SQL as needed of course !

Arno R
Nov 13 '05 #2

Arno R wrote:
"dkintheuk" <rm*******@firenet.uk.com> schreef in bericht news:11*********************@o13g2000cwo.googlegro ups.com...
Hi everyone,

I have a table with a set of accounts in that contains one row for each account for each time it has been audited. (this may not include every account we deal with)

Each month I want to select, from a separate and full list of accounts that i import to the database, a random selection of new accounts to be audited this month. Hence, a row for each one needs to be added to the original database and the most recent entry updated (if it has been
audited before).

I don't want to select an account for re-audit within 3 months (for
example) and the accounts have a category. I want the sample selection to be variable for each category i.e. 12 account of type A, 25 accounts of type B etc.

I'm currently doing this with query upon query upon query (about 16 at the moment) and can't help thinking that there must be a more logical way of doing this in code or maybe by using more effective queries...
I'm looking for advice on the approach i should take not really looking for code samples but will take advice on that if it is provided.

Any good ideas out there?

Thanks,

Rob.


Hi Rob,
If you need 16 query's for this, there is something wrong in your

approch. I think a UNION-query is what you need here.

I suppose you have a table called TblAccounts (AccountID-AccountType) and a Table Called TblAudits (AccountID-AuditDate) (or a query with the last AuditDate for each Account)
3 months is ~ 100 days so something like:

SELECT TOP 12 TblAccounts.AccountID, TblAudits.AuditDate
FROM TblAccounts LEFT JOIN TblAudits ON TblAccounts.AccountID = TblAudits.AccountID WHERE (((TblAudits.AuditDate) Is Null Or (TblAudits.AuditDate)>Date()-100) AND ((TblAccounts.AccountType)="A")) UNION SELECT TOP 25 TblAccounts.AccountID, TblAudits.AuditDate
FROM TblAccounts LEFT JOIN TblAudits ON TblAccounts.AccountID = TblAudits.AccountID WHERE (((TblAudits.AuditDate) Is Null Or (TblAudits.AuditDate)>Date()-100) AND ((TblAccounts.AccountType)="B")) ......
UNION SELECT Top xx ........ where ...... AccountType) = "Z"))

will give you what you need.
You will have to adapt this SQL as needed of course !

Arno R


Arno, Thanks for that,

That's kind of what i thought about but i inherited some of this and
built other parts. Each query is doing a little bit of incremental
change to the data to allow me to work with it.

Of course you're right about the UNION approach. I had though about
that but, guess what, i'd never heard of the TOP function in SQL (never
had need before). That solves a great deal of problems and makes the
query easier to handle.

I will need a cuople of preparatory queries though but now that is far
less onerous. Thanks for the advice can't think why i didn't get closer
befoer... never mind!

Cheers,

Rob.

Nov 13 '05 #3
Just a small update...

I now have to handle this in 3 stages:

1. Prepare the new records so that they have unique random numbers
attached.
2. Prepare the existing table so that i report only one row per account
(even if it has been audited more than once before)
3. Join these together as per your query but make sure I ORDER BY the
unique number so that I force a better random set and append this data
to the original table!

Easy now I come to think about it...

As the categories can vary, i've written a funky loop to handle that
and create the long UNION query before running it.

Good job mate, helped me loads!

Rob.

Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
11
by: nrk | last post by:
Isn't: char s = "--4"; char *endptr; strtol(s, &endptr, 0); supposed to return 0 and set endptr to s? I have run into an implementation (not gcc, gcc does what I expect) that is returning...
1
by: Jim | last post by:
I have created a windows form that contains several tab pages which contain a panels. On a tab page I am trying to dynamically create a series of buttons in that pages panel. I am failing because...
11
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select,...
3
by: Henry | last post by:
I know it is possible to store dynamic propterties for applications in XML files. The app.config and the web.config files can be used to store AppSettings... I am just wondering how far one can...
73
by: JoeC | last post by:
I am writing a game and I am having a challenge with my combat function. All I want to do is find out how to group pieces that are in the same space. There are two sides and all the units that...
3
by: Ara Kooser | last post by:
Hello all, I hope I am posting this correctly. I am running Python 2.4.2 on Slackware 11.0 using IDLE. I am in the process of learning python so I am writing a text adventure game using...
4
by: Ara Kooser | last post by:
I am working on a text adventure game for python to get back into python programming. My version 0.1 used only functions so I could get familiar with how those work. I want to move beyond that. I...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.