• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Access Doable?

Hello All,

Here is the original question where I wanted to added missing rows to the table:
http://www.experts-exchange.com/Database/MS-SQL-Server/Q_28476836.html

But the problem is now this has to happen in access as all users are in that platform and need this to do the same thing but in access (not SQL server)
So after spending some time, I couldn’t figure it out….some TSQL stuff will not work in the access query structure…aint it?
Can anyone guide me. I have attached the access sample DB for reference as well


Within the access file – table “sheet1” is where I want to add the missed rows. Table “sheet2” has all possible week strings


Thank you
SampleDBPlease.zip
0
Rayne
Asked:
Rayne
  • 10
  • 2
  • 2
2 Solutions
 
RayneAuthor Commented:
All Experts are welcomed
0
 
RayneAuthor Commented:
so how can i write a query within access that adds the missed possible rows to sheet1 table...
0
 
RayneAuthor Commented:
something like this? maybe

(SELECT *
from
(select
distinct account,item from sheet1 ) a ,(select [End To End Week] from sheet2) b )

still ...not sure
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
RayneAuthor Commented:
select * from
(SELECT *
from
(select
distinct account,item from sheet1 ) a ,(select [TETEW] from sheet2) b ) E
where E.week not in ("")

not sure again
0
 
RayneAuthor Commented:
The access sql should first find the Cartesian products (all possible combination) of the account, item and week.
 Then the query should only show those combinations of account,item and week that were not originally present in table "sheet1"
0
 
PortletPaulCommented:
In Access that query needs change for coalesce and 'cross join' and convert(null,int)

for the 'cross join' just use a comma between the table names instead

for coalesce() use Nz()

and CInt
select
        dod.Account
      , dod.Item
      , dod.itemDescription
      , dod.[item Grp]
      , wks.week
      , NZ(od.AmountL1,0)     AmountL1
      , NZ(od.AmountK2,0)     AmountK2
      , NZ(od.[dim Length],0) [dim Length]
      , NZ(od.WeekTY,0)       WeekTY
from (
      select distinct
              Account
            , Item
            , itemDescription
            , [item Grp]
            , CInt(null) AmountL1
            , CInt(null) AmountK2
            , CInt(null) [dim Length]
            , CInt(null) WeekTY
      from originalData
     ) dod, "total End to End Weeks" as wks
left join originalData od
      on  dod.Account = od.Account
      and dod.Item = od.Item
      and dod.itemDescription = od.itemDescription
      and dod.[item Grp] = od.[item Grp]
      and wks.week = od.week

Open in new window

I think this may work (but I cannot test this assertion)
0
 
RayneAuthor Commented:
I renamed the tables within access to match them. I have re-attached the DB.

Then your query becomes below the match table names >>
select
        dod.Account
      , dod.Item
      , dod.itemDescription
      , dod.[item Grp]
      , wks.week
      , NZ(od.AmountL1,0)     AmountL1
      , NZ(od.AmountK2,0)     AmountK2
      , NZ(od.[dim Length],0) [dim Length]
      , NZ(od.WeekTY,0)       WeekTY
from (
      select distinct
              Account
            , Item
            , itemDescription
            , [item Grp]
            , CInt(null) AmountL1
            , CInt(null) AmountK2
            , CInt(null) [dim Length]
            , CInt(null) WeekTY
      from originalData
     ) dod, total_End_to_End_Weeks as wks
left join originalData od
      on  dod.Account = od.Account
      and dod.Item = od.Item
      and dod.itemDescription = od.itemDescription
      and dod.[item Grp] = od.[item Grp]
      and wks.week = od.week
0
 
RayneAuthor Commented:
0
 
RayneAuthor Commented:
still not working
0
 
PortletPaulCommented:
all I can suggest is "starting small"

The principle of the overall query is you need the Cartesian product of 2 tables (a "cross join")

e.g.

select * from originalData, total_End_to_End_Weeks

if that works the substitute the "derived table"

select * from (
select distinct
              Account
            , Item
            , itemDescription
            , [item Grp]
            , CInt(null) AmountL1
            , CInt(null) AmountK2
            , CInt(null) [dim Length]
            , CInt(null) WeekTY
      from originalData
     ) dod
, total_End_to_End_Weeks

Then the left join. In other words build it upward to the desired result, and along the way the problems will be easier to identify (they will belong to the part you just added into the query).

Make sense?

pl. note I don't have or use Access so a .accdb is 6 characters to me
0
 
als315Commented:
In Access you can use sequental queries. Look at sample. Query qryAppend2 will add missing rows to your table. I've modified your table with weeks, because in text compare fweek2 > fweek10. I've added decimal number of week.
SampleDBPlease22.accdb
0
 
RayneAuthor Commented:
Thank you Portlet Paul, your logic makes sense.

Als315 – thank you your solution fits it. Can you explain how you did it?
Thanks again….this does what I wanted….
0
 
als315Commented:
You need a series of queries:
1. Select all possible combinations of Accounts and Items (there is only one account in your sample, so I have no enough information about possible combinations) - qryItems
2. Query with combination of results of first query and weeks - qryCombinations
3. Missing weeks (qryAppend)
4. Find values from last week before missing (here we need number of week, because we need to order them) - qryAppend1
5. Add values - qryAppend2
0
 
RayneAuthor Commented:
thank you all
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 10
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now