October 16, 2009 at 8:56 am
I am posting this to the "newbie" forum and I know it should be in the T-SQL forum possibly, but my limited exposure to complicated procedures makes me a "newbie" I would gather.
Anyway, here is the problem. I have a main table that is being populated by a stored procedure and all is well there. I need to do a subselect from this table and here is the problem and I don't know how to do it. The table has a row for the scheduled number of products to be produced (ScheduledCases) and another calculated column called CurrentGluedStockPieces. I am assuming because the latter column is calculated, this calculated value is the same for each row and that is okay with me. However, now what I need to do is when CurrentGluedStockPieces is less than ScheduledCases I need to return the value of two other columns (StartDate and Shift).
How would I write a query to got through each row from this main table (based on the current date), accumluate a variable for Scheduled and once a row's scheduled value is greater than the CurrentGluedStockPiece value, return that row's StartDate and Shift value.
I hope this makes sense and I can expound more if needed.
Thanks for the information.
October 16, 2009 at 9:07 am
You wouldn't use a variable, and you wouldn't go through each row.
If I understand, what you likely want to do is use a CASE statement for the other fields. In the CASE, you have a WHEN clause. In there, use an expression, WHEN CurrentGluedStockPieces < ScheduledCases.
The clause has a "THEN", which returns data. You can return the fields you need in there. If the other case is try (CurrentGluedStockPieces >= ScheduledCases), you can return nothing, dummy data, etc.
October 16, 2009 at 9:15 am
Please post table definitions, sample data and desired output. Read this to see the best way to post this to get quick responses.
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 16, 2009 at 11:41 am
Thanks Steve for the reply. I enjoy reading your editorials every morning. Anyway, basically what I need to do is to "aggregate" or accumulate the value from Scheduled and once that aggreagated value is more than the value of CurrentGluedInventory, then I need to select the StartDate from that row where the Scheduled number is more than CurrentGluedInventory.
If I were writing this in VB Code I would know exactly what I would need to do. Unfortunately, my lack of experience writing stored procs is holding this project up and the project is for a Report in SSRS.
Thanks again!
October 16, 2009 at 12:27 pm
I think you'll need to show us some samples and ideas. I'm not quite clear what you mean by aggregating. If you are adding up previous rows, what's a previous row? Based on dates? I was thinking that the calculated column was valid for each row.
Thanks for the complement. Glad to get your day started.
October 16, 2009 at 12:55 pm
Okay, here it goes:
The raw data for just one case code (02725). The actual raw table contains close to 500 rows with different case codes:
ScheduledDate Shift CaseCode Scheduled StartDate CurrentGluedPieces
2009-10-22 00:00:00.000102725 12592009-10-22 00:00:00.00015750
2009-10-22 00:00:00.000202725 12592009-10-22 00:00:00.00015750
2009-10-22 00:00:00.000302725 12592009-10-22 00:00:00.00015750
2009-10-23 00:00:00.000102725 37502009-10-22 00:00:00.00015750
2009-10-23 00:00:00.000202725 18752009-10-22 00:00:00.00015750
2009-10-23 00:00:00.000202725 18752009-10-22 00:00:00.00015750
2009-10-23 00:00:00.000302725 18752009-10-22 00:00:00.00015750
2009-10-23 00:00:00.000302725 18752009-10-22 00:00:00.00015750
2009-10-24 00:00:00.000102725 18752009-10-22 00:00:00.00015750
2009-10-24 00:00:00.000102725 18752009-10-22 00:00:00.00015750
2009-10-24 00:00:00.000202725 18752009-10-22 00:00:00.00015750
2009-10-24 00:00:00.000202725 18752009-10-22 00:00:00.00015750
2009-10-24 00:00:00.000302725 18752009-10-22 00:00:00.00015750
2009-10-24 00:00:00.000302725 18752009-10-22 00:00:00.00015750
I don't need to group by case code, but I need to accumulate the Scheduled number for each case code and when that number is greater than CurrentGluedPieces, I need to select that row's StartDate. For instance, the very first row's scheduled number is 1259. The next one is 1259 for a total of 2518; the next value is another 1259 for a total of 3,777. The glued stock total is 15,750. Once the scheduled total is greater than 15,750 (which happens to be the ninth row and the total would be 16,902), I need the StartDate for that row returned, which would happen to be 10/22/2009.
As a side note: some of the rows appear to be doubling, but this is because a certain product (case code) can be run at the same time on more than one line.
I hope this made it a bit clearer as I provided the raw data and the desired result (which would be the StartDate). Once I get the startDate, I further have to do a datediff, but that is the easy part.
Thanks,
Brad
October 16, 2009 at 1:53 pm
Brad,
This appears to be a "simple" running total problem. If you'd take the time to format the data in a readily consumable format along with a CREATE TABLE statement, I'm pretty sure I can help... please see the first link in my signature below for how to easily provide that format. Thanks.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 19, 2009 at 6:28 am
Jeff,
Thanks for the reply. I reviewed your article and took the time to create the temp table and insert the data there. Here it is:
IF OBJECT_ID('TempDB..#tempGlue','U') IS NOT NULL
DROP TABLE #tempGlue
CREATE TABLE #tempGlue
(
ScheduledDate datetime,
Shift char(1),
CaseCode char(10),
Scheduled int,
StartDate datetime,
CurrentGluedPieces int
)
SET DATEFORMAT DMY
INSERT INTO #tempGlue (ScheduledDate, Shift, CaseCode, Scheduled, StartDate, CurrentGluedPieces)
select 'Oct 16 2009 ','1','37991 ','2540','Oct 16 2009 ','27000'UNION ALL
select 'Oct 16 2009 ','1','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 16 2009 ','1','37991 ','2540','Oct 16 2009 ','27000'UNION ALL
select 'Oct 16 2009 ','2','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 16 2009 ','1','37991 ','2540','Oct 16 2009 ','148500'UNION ALL
select 'Oct 16 2009 ','2','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 16 2009 ','1','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 16 2009 ','3','37991 ','2667','Oct 16 2009 ','27000'UNION ALL
select 'Oct 16 2009 ','1','37991 ','2667','Oct 16 2009 ','27000'UNION ALL
select 'Oct 16 2009 ','3','37991 ','2582','Oct 16 2009 ','148500'UNION ALL
select 'Oct 16 2009 ','1','37991 ','2667','Oct 16 2009 ','27000'UNION ALL
select 'Oct 16 2009 ','3','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 16 2009 ','1','37991 ','2667','Oct 16 2009 ','148500'UNION ALL
select 'Oct 17 2009 ','1','31828 ','1714','Oct 16 2009 ','283500'UNION ALL
select 'Oct 16 2009 ','1','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 17 2009 ','1','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 16 2009 ','1','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 17 2009 ','2','24329 ','2083','Oct 16 2009 ','88110'UNION ALL
select 'Oct 16 2009 ','2','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 17 2009 ','2','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 16 2009 ','2','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 17 2009 ','2','31828 ','676','Oct 16 2009 ','283500'UNION ALL
select 'Oct 16 2009 ','3','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 17 2009 ','3','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 16 2009 ','3','37991 ','2667','Oct 16 2009 ','148500'UNION ALL
select 'Oct 17 2009 ','3','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 16 2009 ','3','31828 ','1714','Oct 16 2009 ','283500'UNION ALL
select 'Oct 18 2009 ','1','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 17 2009 ','1','37991 ','4825','Oct 16 2009 ','27000'UNION ALL
select 'Oct 18 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 17 2009 ','2','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 18 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 17 2009 ','2','31828 ','1714','Oct 16 2009 ','283500'UNION ALL
select 'Oct 18 2009 ','2','31828 ','1714','Oct 16 2009 ','283500'UNION ALL
select 'Oct 17 2009 ','2','31920 ','4000','Oct 17 2009 ','63840'UNION ALL
select 'Oct 18 2009 ','2','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 17 2009 ','3','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 18 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 17 2009 ','3','24329 ','5521','Oct 16 2009 ','88110'UNION ALL
select 'Oct 19 2009 ','1','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 17 2009 ','3','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 19 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 17 2009 ','3','24329 ','5243','Oct 16 2009 ','88110'UNION ALL
select 'Oct 19 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 17 2009 ','3','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 19 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 18 2009 ','1','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 19 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 18 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','1','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 18 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','1','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 18 2009 ','1','31828 ','1714','Oct 16 2009 ','283500'UNION ALL
select 'Oct 20 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 18 2009 ','3','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 20 2009 ','1','31833 ','1905','Oct 16 2009 ','140400'UNION ALL
select 'Oct 18 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','2','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 18 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 18 2009 ','3','31828 ','1714','Oct 16 2009 ','283500'UNION ALL
select 'Oct 20 2009 ','2','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 18 2009 ','3','31833 ','1467','Oct 16 2009 ','140400'UNION ALL
select 'Oct 20 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 19 2009 ','1','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 20 2009 ','2','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 19 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','3','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 19 2009 ','1','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 20 2009 ','3','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 19 2009 ','1','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 20 2009 ','3','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 19 2009 ','2','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 20 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 19 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','3','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 19 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 21 2009 ','1','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 19 2009 ','2','31833 ','1905','Oct 16 2009 ','140400'UNION ALL
select 'Oct 21 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 19 2009 ','3','31828 ','1204','Oct 16 2009 ','283500'UNION ALL
select 'Oct 21 2009 ','1','31828 ','631','Oct 16 2009 ','283500'UNION ALL
select 'Oct 20 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 21 2009 ','1','31920 ','11500','Oct 17 2009 ','63840'UNION ALL
select 'Oct 20 2009 ','1','31828 ','631','Oct 16 2009 ','283500'UNION ALL
select 'Oct 21 2009 ','2','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 20 2009 ','1','31920 ','11500','Oct 17 2009 ','63840'UNION ALL
select 'Oct 21 2009 ','2','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 20 2009 ','2','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 21 2009 ','2','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 20 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 21 2009 ','2','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 20 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 21 2009 ','3','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 20 2009 ','3','31828 ','631','Oct 16 2009 ','283500'UNION ALL
select 'Oct 21 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 20 2009 ','3','31920 ','11500','Oct 17 2009 ','63840'UNION ALL
select 'Oct 21 2009 ','3','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 21 2009 ','1','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 21 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 21 2009 ','1','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 21 2009 ','3','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 21 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 22 2009 ','1','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 21 2009 ','1','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 22 2009 ','1','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 21 2009 ','2','31828 ','631','Oct 16 2009 ','283500'UNION ALL
select 'Oct 22 2009 ','1','31843 ','3900','Oct 16 2009 ','110250'UNION ALL
select 'Oct 21 2009 ','2','31920 ','11500','Oct 17 2009 ','63840'UNION ALL
select 'Oct 22 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 21 2009 ','3','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 22 2009 ','1','02713 ','2233','Oct 22 2009 ','70200'UNION ALL
select 'Oct 21 2009 ','3','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 22 2009 ','1','51002 ','3656','Oct 16 2009 ','229320'UNION ALL
select 'Oct 22 2009 ','1','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 22 2009 ','2','29119 ','4074','Oct 16 2009 ','91520'UNION ALL
select 'Oct 22 2009 ','1','31828 ','631','Oct 16 2009 ','283500'UNION ALL
select 'Oct 22 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'UNION ALL
select 'Oct 22 2009 ','1','31920 ','11500','Oct 17 2009 ','63840'UNION ALL
select 'Oct 22 2009 ','2','02725 ','1259','Oct 22 2009 ','15750'UNION ALL
select 'Oct 22 2009 ','2','29119 ','4074','Oct 16 2009 ','0'UNION ALL
select 'Oct 22 2009 ','2','02713 ','2233','Oct 22 2009 ','70200'UNION ALL
select 'Oct 22 2009 ','2','24329 ','3588','Oct 16 2009 ','88110'
select * from #tempGlue
Now, here I am just selecting all from the #tempGlue table; what I need the help with is the running totals as you mentioned.
Hope you can help and thanks again!
Brad
October 19, 2009 at 7:30 pm
Thanks Brad... just got home from work and looking at this now...
--Jeff Moden
Change is inevitable... Change for the better is not.
October 19, 2009 at 7:51 pm
Ok, I guess I have a question or two...
If a Case code (like 29119) has two values of CurrentGluedPieces of 0 and 91520 for each day and shift, how do you want to handle it?
Likewise but slightly different, if a Case code (like 37991) has two values of CurrentGluedPieces of 27000 and 148500, ho do you want to handle it?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 20, 2009 at 4:17 am
The reason that there might be two different values is due to another column that was not included called CartonCopy. A product (CaseCode) might have two or even three CartonCopys being run during the schedule due to different promotions going on. For this purpose though, that value should be summed.
October 22, 2009 at 5:10 am
Jeff, wondering if you were still able to help with this. I have had a busy couple of days, but I will be revisiting this project this afternoon.
Thanks,
Brad
October 22, 2009 at 5:59 am
Brad Allison (10/22/2009)
Jeff, wondering if you were still able to help with this. I have had a busy couple of days, but I will be revisiting this project this afternoon.Thanks,
Brad
Hi Brad,
Yep... I've been pretty busy myself but I can help tonight after work (on my way there now). From what you've stated, the CartonCopy provides some additional uniqueness that I'll need to find the correct overall total to hit. Any chance of you regenning the Insert/Select code to create the data for #TempGlue like you did before except include CartonCopy as well? Thanks.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 22, 2009 at 10:26 am
Jeff, I really appreciate this help. Here it is with the CartonCopy included:
IF OBJECT_ID('TempDB..#tempGlue','U') IS NOT NULL
DROP TABLE #tempGlue
CREATE TABLE #tempGlue
(
ScheduledDate datetime,
Shift char(1),
CaseCode char(10),
CartonCopy char(10),
Scheduled int,
StartDate datetime,
CurrentGluedPieces int
)
SET DATEFORMAT DMY
INSERT INTO #tempGlue (ScheduledDate, Shift, CaseCode, CartonCopy, Scheduled, StartDate, CurrentGluedPieces)
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2540','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2540','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2540','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','37991 ','9925Q','2582','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','24329 ','4329Q','2083','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','31828 ','1828E','676','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','37991 ','9925G','4825','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','31920 ','7157G','4000','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','24329 ','4329Q','5521','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','24329 ','4329Q','5243','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','31833 ','1833P','1905','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','31833 ','1833P','1905','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','31828 ','1828E','1204','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','02713 ','0277B','2233','Oct 22 2009 12:00AM','70200' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','02725 ','0272C','1259','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','02713 ','0277B','2233','Oct 22 2009 12:00AM','70200' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','02725 ','0272C','1259','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','02713 ','0277B','2233','Oct 22 2009 12:00AM','70200' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','02725 ','0272C','3750','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','24329 ','4329Q','3125','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','24329 ','4329Q','3216','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','31828 ','1828E','1704','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','29119 ','9119M','3907','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','31828 ','1828E','1704','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','31828 ','1828E','874','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2540','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2540','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2540','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','31833 ','1833P','1467','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','37991 ','9925G','3962','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925G','2667','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','37991 ','9925Q','3962','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','37991 ','9925Q','2667','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','37991 ','9925G','3911','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','00109 ','0109B','1322','Oct 16 2009 12:00AM','44325' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','1','20738 ','0738B','945','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','37991 ','9925Q','3911','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 16 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','37991 ','9925G','2582','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 16 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','37991 ','9925Q','2311','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','24329 ','4329Q','4167','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','1','37991 ','9925Q','4825','Oct 16 2009 12:00AM','148500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','24329 ','4329Q','5521','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','37991 ','9925G','2311','Oct 16 2009 12:00AM','27000' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 17 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 17 2009 12:00AM','3','31828 ','1828E','1714','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 18 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 18 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','31828 ','1828E','1204','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 18 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','31833 ','1833P','1905','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','31828 ','1828E','1204','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 19 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','29119 ','9119M','4074','Oct 16 2009 12:00AM','91520' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','31833 ','1833P','1905','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 19 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','29119 ','9119H','4074','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','31843 ','1843C','3900','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','31828 ','1828E','1204','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','31833 ','1833P','1905','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 19 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','1','31828 ','1828E','1204','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','2','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','31828 ','1828E','792','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 20 2009 12:00AM','3','31833 ','1833P','1524','Oct 16 2009 12:00AM','140400' UNION ALL
SELECT 'Oct 21 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','31843 ','1843C','2761','Oct 16 2009 12:00AM','110250' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','24329 ','4329Q','3750','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','24329 ','4329Q','3125','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','24329 ','4329Q','3125','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 21 2009 12:00AM','2','24329 ','4329Q','3889','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','31828 ','1828E','856','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 21 2009 12:00AM','3','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','31828 ','1828E','857','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 25 2009 12:00AM','1','51002 ','H2H03','700','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 22 2009 12:00AM','1','02725 ','0272C','1259','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','31828 ','1828E','1722','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 25 2009 12:00AM','3','31828 ','1828E','1722','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 22 2009 12:00AM','3','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','31828 ','1828E','631','Oct 16 2009 12:00AM','283500' UNION ALL
SELECT 'Oct 23 2009 12:00AM','1','31920 ','7157G','11500','Oct 17 2009 12:00AM','63840' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','24329 ','4329Q','3588','Oct 16 2009 12:00AM','88110' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 23 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 23 2009 12:00AM','3','31845 ','1845A','3500','Oct 23 2009 12:00AM','6795' UNION ALL
SELECT 'Oct 24 2009 12:00AM','1','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 24 2009 12:00AM','2','51002 ','H2H03','3656','Oct 16 2009 12:00AM','229320' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','29119 ','9119H','3907','Oct 16 2009 12:00AM','0' UNION ALL
SELECT 'Oct 24 2009 12:00AM','3','02725 ','0272C','1875','Oct 22 2009 12:00AM','15750' UNION ALL
SELECT 'Oct 25 2009 12:00AM','2','29119 ','9119H','3907','Oct 16 2009 12:00AM','0'
select * from #tempGlue
Brad
October 22, 2009 at 9:57 pm
Steve Jones - Editor (10/16/2009)
You wouldn't use a variable, and you wouldn't go through each row.If I understand, what you likely want to do is use a CASE statement for the other fields. In the CASE, you have a WHEN clause. In there, use an expression, WHEN CurrentGluedStockPieces < ScheduledCases.
The clause has a "THEN", which returns data. You can return the fields you need in there. If the other case is try (CurrentGluedStockPieces >= ScheduledCases), you can return nothing, dummy data, etc.
Ummmm.... not quite true. Although you could certainly do it with inequalities, that would constitute a very resource intensive, comparitively super slow "Triangular Join". To see why that's such a very bad thing to do, please see the following article...
http://www.sqlservercentral.com/articles/T-SQL/61539/
There are only 4 effective ways to do a running total and they are all procedureal...
1. Cursor (about 8 minutes per million rows but much faster than the hours/days Triangular Joins take)
2. While Loop (ties with Cursor when the cursor is written properly)
3. CLR (also known as a major "PITA" in the Moden Tribe ;-))
4. A "Quirky Update" which uses a procedural "Pseudo Cursor" behind the scenes that will do a million rows in something less than 7 seconds.
Speaking of "Quirky Updates", guess what I've included in the code in the post below? 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 15 posts - 1 through 15 (of 25 total)
You must be logged in to reply to this topic. Login to reply