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
RayneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
PortletPaulfreelancerCommented:
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
PortletPaulfreelancerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RayneAuthor Commented:
thank you all
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.