Showing posts with label bit. Show all posts
Showing posts with label bit. Show all posts

Friday, March 30, 2012

query help

Here is a simplified example of what I need to accomplish.

I have a table that keeps track of plastic balls in tubs. Based on a bit column the record is either defining balls added to a tub or taken away. When the record is defined as adding balls to a tub it will say how many and what color, but when the flag says they have been taken away from a tub I only know the number removed and not the color.

There are multiple tubs and multiple colors. So say tub1 has 20 balls in it (50% red, %25 green, and %25 blue). Also say tub2 has 10 balls in it (100% red). This is our starting point.

Now on day one, 5 balls from tub two are put into tub one. So we know that 5 balls of 100% red are put into tub one. This means that tub one now has 25 balls in it. By doing some weighted percentages, tub one now has these percentages: red = 60%, green = 20%, and blue = 20%.

Say on day two however, 5 balls are removed from tub one and placed back into tub two. We cannot say anything about the colors, but that they are: .6red, .2green, and .2 blue. So if we want a percentage for tub two on day 2 we now get: .8red, .1green and .1blue.

The math for the new percentage is I believe = ((originalPercent * originalCount) + (addedPercent * addedAmount)) / newTotalBallCount

I need a query that will give me the percentages of the different colors in the tub for any given day. This is really a running percentage that has to take every transaction into account.

This is a complicated query fro me to figure out, but can someone point me in the right direction?

LLeuthard wrote:

Say on day two however, 5 balls are removed from tub one and placed back into tub two. We cannot say anything about the colors, but that they are: .6red, .2green, and .2 blue. So if we want a percentage for tub two on day 2 we now get: .8red, .1green and .1blue.

too superfluous.

is this thing about permutation and combination/? how did u say taht 6r,2g,2b?

|||Are you saying it is not worth my time or that it is impossible? Is there a stored proc I could write that would do this easily?|||

I got .6Red .2Blue and .2Green by saying that:

5 balls of 100% red were moved to tub1. so tub1 originally has a estimate of .5*20 = 10Red balls.

Take the estimate of 10Red and add the estimate of 5Red and we get an estimate of 15Red out of 25 in tub1. This makes for .6Red at the end of day 1.

Do the same with the others.

Saturday, February 25, 2012

Query Builder Tool

Hello -- does anyone know of any good tools to create queries for SQL
Server? I'm currently using Query Analzyer, but would like something a bit
more QUI oriented similar to what Access has -- where I can insert tables
and drag columns, etc.
Any help would be appreciated.Hello DavidM.
You can use Enterprise Manager for an interface very similar to Access.
Click the tables node to get a listing of all the tables in the right pane.
Select a table and right click. Select open table from the pop up menu.
Select Query. You should now see an interface like Access that you can use to
design queries.
regards,
Mark Baekdal
http://www.dbghost.com
+44 (0)208 241 1762
Database change management for SQL Server
"DavidM" wrote:
> Hello -- does anyone know of any good tools to create queries for SQL
> Server? I'm currently using Query Analzyer, but would like something a bit
> more QUI oriented similar to what Access has -- where I can insert tables
> and drag columns, etc.
> Any help would be appreciated.
>
>|||Probably the best (and easiest) one I've seen is Crystal Reports.
--
Regards,
Hank Arnold
"DavidM" <spam@.spam.net> wrote in message
news:OoefkbD$EHA.3908@.TK2MSFTNGP12.phx.gbl...
> Hello -- does anyone know of any good tools to create queries for SQL
> Server? I'm currently using Query Analzyer, but would like something a
> bit more QUI oriented similar to what Access has -- where I can insert
> tables and drag columns, etc.
> Any help would be appreciated.
>
>|||This one seems nice --
http://www.sqlmanager.net/products/mssql/query
"Hank Arnold" <rasilon@.aol.com> wrote in message
news:351eeqF4fnrjtU1@.individual.net...
> Probably the best (and easiest) one I've seen is Crystal Reports.
> --
> Regards,
> Hank Arnold
> "DavidM" <spam@.spam.net> wrote in message
> news:OoefkbD$EHA.3908@.TK2MSFTNGP12.phx.gbl...
>> Hello -- does anyone know of any good tools to create queries for SQL
>> Server? I'm currently using Query Analzyer, but would like something a
>> bit more QUI oriented similar to what Access has -- where I can insert
>> tables and drag columns, etc.
>> Any help would be appreciated.
>>
>