Hi guys! I've got the following problem.
I have a query that pulls data from several tables.
After I run the query the date in the "Month/yr_1" field is populated for some records and is NULL for others).
The ones that are populated show the same date(eg. all records in the "Month/yr_1" field show date - "4/8/2006").
What I want to do is this:
- For the records that show "NULL" in the "Month/yr_1" field I want to populate them with the date that shows in the records that are populated.
- I want to use some kind of random function that goes to a specific field in the table where all records show the same date and pull one of those date values randomly so I can populate my blank or "NULL" "Month/yr_1" field with that particular date.
Here the code for that query:
Here the Output:
As you can see I want to populate the "NULLs" with 4/8/2006 by extracting that date randomly from "Counts" table. Hope this is not too messy and you can understand what I'm trying to accomplish.
PS. In the output I have hidden the fields that bear no importance.
Thank you very much!
Valeriya
I have a query that pulls data from several tables.
After I run the query the date in the "Month/yr_1" field is populated for some records and is NULL for others).
The ones that are populated show the same date(eg. all records in the "Month/yr_1" field show date - "4/8/2006").
What I want to do is this:
- For the records that show "NULL" in the "Month/yr_1" field I want to populate them with the date that shows in the records that are populated.
- I want to use some kind of random function that goes to a specific field in the table where all records show the same date and pull one of those date values randomly so I can populate my blank or "NULL" "Month/yr_1" field with that particular date.
Here the code for that query:
Code:
[b]SELECT DISTINCT[/b] [0005 Bins with SOD].GDS, [0005 Bins with SOD].DAM, [0005 Bins with SOD].DAMMgr, [0005 Bins with SOD].REP, [0005 Bins with SOD].AcctName, [0005 Bins with SOD].Cust, [0005 Bins with SOD].BinCls, [0005 Bins with SOD].Bin, [0005 Bins with SOD].ShortItemNbr, [0005 Bins with SOD].Item AS ItemNumber, [0005 Bins with SOD].Description, [0005 Bins with SOD].Maj, [0005 Bins with SOD].Min, [0005 Bins with SOD].QtyOnHand, Trim([0005 Bins with SOD].[ID]) AS [ID#], [0005 Bins with SOD].DateUpdated, [0005 Bins with SOD].ExpDate, [0005 Bins with SOD].OrderType, [0005 Bins with SOD].OrderNbr, [0005 Bins with SOD].Reference, [0005 Bins with SOD].OrderDt, [0005 Bins with SOD].Ship, [0005 Bins with SOD].StatusCodeNext, Counts.ID, Counts.Comment AS Counts_Comment, Counts.[Month/Yr], Counts_1.[Month/Yr] AS [Month/Yr_1],
IIf([counts].[month/yr] Is Null,IIf([ship] Between counts_1.[month/yr]-10 And counts_1.[month/yr],"Replenish",
IIf(counts_1.[month/yr]<[ship],"Ship After Count","NOT COUNTED")),"") [b]AS[/b] Comment [b]INTO[/b] [0006 In Bin and Not Counted]
[b]FROM[/b]([0005 Bins with SOD] [b]LEFT JOIN[/b] Counts ON ([0005 Bins with SOD].Cust = Counts.Cust) AND ([0005 Bins with SOD].ID = Counts.ID))
[b]LEFT JOIN[/b]Counts[b] AS[/b] Counts_1 [b]ON[/b] [0005 Bins with SOD].Cust = Counts_1.Cust
[b]WHERE[/b] ((([0005 Bins with SOD].QtyOnHand)>0) [b]AND[/b] (([0005 Bins with SOD].StatusCodeNext)<"300") [b]AND[/b] ((Counts.ID) Is Null) [b]AND [/b]((IIf([counts].[month/yr] Is Null,
IIf([ship] [b]Between[/b] [counts_1].[month/yr]-10 And [counts_1].[month/yr],"Replenish",
IIf([counts_1].[month/yr]<[ship],"Ship After Count","NOT COUNTED")),"")) Not Like "Ship*"))
[b]ORDER BY[/b] Trim([0005 Bins with SOD].[ID]);
Here the Output:
Cust ID# Ship Month/Yr_1 Comment
2136 020589 6/8/2004 NOT COUNTED
5822 021009 6/2/2005 4/8/2006 NOT COUNTED
1771 030054 3/30/2006 NOT COUNTED
1771 030054 3/30/2006 4/8/2006 Replenish.
3178 030397 12/21/2005 NOT COUNTED
1564 030596 3/15/2006 NOT COUNTED
3575 034133 12/9/2005 4/8/2006 NOT COUNTED
1622 034559 2/23/2006 NOT COUNTED
1564 040027 3/15/2006 NOT COUNTED
1127 040028 12/22/2004 4/8/2006 NOT COUNTED
3575 040035 3/23/2006 4/8/2006 NOT COUNTED
3575 040035 3/23/2006 4/8/2006 NOT COUNTED
As you can see I want to populate the "NULLs" with 4/8/2006 by extracting that date randomly from "Counts" table. Hope this is not too messy and you can understand what I'm trying to accomplish.
PS. In the output I have hidden the fields that bear no importance.
Thank you very much!
Valeriya