removing table from MS Access Query - ms-access

I have a broken Access query and the reason it is broken is that one of the tables it is referencing doesn't exist so I can't see the query in design view - problem is I normally work in SQL Server and some of the formatting is bizarre to me - I need to take out all references to 'RMS_Import' table - any ideas?
Thanks!
SELECT Temp_LockedList.DEPARTMENT, PO_EmployeeName.Employee, PO_EmployeeName.BU, PO_EmployeeName.[PO Type], Temp_LockedList.STOCK_CATEGORY, Temp_LockedList.PO_NUMBER, Temp_LockedList.MATERIAL, Temp_LockedList.DESCRIPTION, Temp_LockedList.PO_ISSUE_DATE, Date()-[PO_ISSUE_DATE] AS [Days Since Issue], Temp_LockedList.PO_REQ_SHIP_DATE, IIf([LT] Is Null,IIf([dbo_articlenumbers].[LeadTime] Is Null,[rms_info].[leadtime],[dbo_articlenumbers].[LeadTime]),[LT]) AS [Prod LT], Temp_LockedList.PO_ORDERED_QUANTITY, Temp_LockedList.PO_BALANCE_QUANTITY, Temp_LockedList.Color, Temp_LockedList.ORIGINAL_SEASON, Temp_LockedList.CURRENT_SEASON, Temp_LockedList.LAUNCH_DATE, Temp_LockedList.WORKING_NUMBER, Temp_LockedList.IB_LOCK, Temp_LockedList.ORDER_PRIORITY_INDICATOR, Temp_LockedList.RANGE_TYPE_DESC, IIf([ActivationStatus] Is Null,[Lifecycle1] & "/" & [LO_Track1],[ActivationStatus]) AS [Activation Status / Prod Stat / Dev- LO], IIf([SignoffDate] Is Null,[RMS_Info].[Buy Ready],[SignoffDate]) AS [Buy Ready Date/ Sign off Date], RMS_Import.long_descr, RMS_Import.ret_from, RMS_Import.ret_to, IIf([MinOfCreateDate] Is Null,Date(),[MinOfCreateDate]) AS [First Shown on rpt], IIf(IsNull([LockedList - 2].[US PO #]),Null,"x") AS [In prior rpt]
FROM ((((((Temp_LockedList LEFT JOIN dbo_ArticleNumbers ON Temp_LockedList.MATERIAL = dbo_ArticleNumbers.ArticleNumber) LEFT JOIN PO_EmployeeName ON (Temp_LockedList.PO_NUMBER = PO_EmployeeName.PO_NUMBER) AND (Temp_LockedList.PO_ITEM_NUMBER = PO_EmployeeName.PO_ITEM_NUMBER) AND (Temp_LockedList.MATERIAL = PO_EmployeeName.MATERIAL)) LEFT JOIN RMS_Info ON Temp_LockedList.MATERIAL = RMS_Info.Article) LEFT JOIN [LockedList - 2] ON (Temp_LockedList.PO_NUMBER = [LockedList - 2].[US PO #]) AND (Temp_LockedList.MATERIAL = [LockedList - 2].Article)) LEFT JOIN [LockedList - 4] ON (Temp_LockedList.PO_NUMBER = [LockedList - 4].[US PO #]) AND (Temp_LockedList.MATERIAL = [LockedList - 4].Article)) LEFT JOIN RMS_Import ON Temp_LockedList.MATERIAL = RMS_Import.artnr) LEFT JOIN exceptions ON Temp_LockedList.PO_NUMBER = exceptions.[SAP PO NUMBER]
ORDER BY Temp_LockedList.DEPARTMENT, Temp_LockedList.PO_NUMBER, Temp_LockedList.MATERIAL;

A quick and dirty GUI way would be to just make a table RMS_Import edit the query, use the editor to remove it from the query, save the query and then delete the RMS_Import table
Manually you should be able to just remove the text LEFT JOIN RMS_Import ON Temp_LockedList.MATERIAL = RMS_Import.artnr from the query string - it's flanked by parenthesis so it's easy to single out
In both cases you will have unreferenced columns that will prompt for user input each time until you remove them from the query editor columns

Related

How to pull in null values when searching for specific document name

I am having issues pulling in null values in my query. I am looking for patients who have a specific document name in their chart but also want to show patients who do not have this specific document name as well. Right now my code is only pulling in the patients with the document name History and Physical (Transcription) but I need to see Null values as well. Below is my code:
snip of code
SELECT CV3ClientVisit.ClientDisplayName, CV3ClientVisit.CurrentLocation, CV3ClientVisit.IDCode, CV3ClientVisit.VisitIDCode, CV3ClientVisit.VisitStatus, CV3ClientVisit.TypeCode, CV3ClientDocumentCUR.DocumentName
FROM CV3ClientVisit INNER JOIN
CV3ClientDocumentCUR ON CV3ClientVisit.GUID = CV3ClientDocumentCUR.ClientVisitGUID
WHERE (CV3ClientVisit.VisitStatus = 'ADM') AND (CV3ClientVisit.TypeCode = 'INPATIENT ADMIT') AND (CV3ClientDocumentCUR.DocumentName = 'History & Physical (transcription)' OR CV3ClientDocumentCUR.DocumentName IS NULL )
Use a LEFT JOIN with the condition in the ON clause:
SELECT cv.ClientDisplayName, cv.CurrentLocation, cv.IDCode,
cv.VisitIDCode, cv.VisitStatus, cv.TypeCode, cd.DocumentName
FROM CV3ClientVisit cv LEFT JOIN
CV3ClientDocumentCUR cd
ON cv.GUID = cd.ClientVisitGUID AND
cd.DocumentName = 'History & Physical (transcription)'
WHERE cv.VisitStatus = 'ADM' AND
cv.TypeCode = 'INPATIENT ADMIT' ;
I also added table aliases to simplify the query.

DOMO - MYSQL Transformation Database table error

I'm Trying to replicate queries on DOMO from microsoft acccess. I assumed I had got the correct syntax but now I'm getting a The database reported a syntax error. Not unique table/alias: 'ga_wip_due_within_one_week'
SELECT `egl_inv`.Category, `egl_inv`.StyleClass, `egl_inv`.StyleMaster,
`egl_inv`.StyleMasterDesc, `egl_inv`.Color, `egl_inv`.ColorDesc,
`egl_inv`.Size,`egl_inv`.GscSku, `egl_inv`.UPC, `egl_inv`.RedistributionFlag,
`egl_inv`.Date_Soldout, `egl_inv`.GGS, `egl_inv`.Core, `egl_inv`.CartonQty,
If(IsNull(`ga_inv`.SumOfQty=True),0,`ga_inv`.SumOfQty) AS GA_INV,
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True),
0,`ga_wip_due_within_one_week`.SumOfQty_Size_Open) AS GA_WIP,
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True)
,0,`ga_wip_due_within_one_week`.`SumOfQty_Size_Open`.SumOfQty_Size) AS CUT,
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`) AS SS,
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`.`Demand`) AS
Demand, If(IsNull(`openorder`.OpenOrders=True),0,`openorder`.OpenOrders) AS
OpenOrders, If(IsNull(`egl_inv`.SumOfQty=True),0,`egl_inv`.SumOfQty) AS
EGL_INV,
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`.Demand)
AS AvgWklyFcst
FROM `averageweeklyfcst`
RIGHT JOIN (OpenOrders RIGHT JOIN (((((`egl_inv`
LEFT JOIN `ga_inv`ON `egl_inv`.GscSku = `ga_inv`.GscSku)
LEFT JOIN `ga_wip_due_within_one_week` ON `egl_inv`.GscSku =
`ga_wip_due_within_one_week`.GscSku) LEFT JOIN `ga_wip_due_within_one_week`
ON `egl_inv`.GscSku = `ga_wip_due_within_one_week`.GscSku)
LEFT JOIN `averageweeklyfcst` ON `
egl_inv`.GscSku = `averageweeklyfcst`.GscSku)
LEFT JOIN Demand ON `egl_inv`.GscSku = `averageweeklyfcst`.GscSku) ON
`openorder`.GscSku = `egl_inv`.GscSku) ON
`averageweeklyfcst`.GscSku = `egl_inv`.GscSku
GROUP BY EGL_INV.Category, `egl_inv`.StyleClass, `egl_inv`.StyleMaster,
`egl_inv`.StyleMasterDesc, `egl_inv`.Color, `egl_inv`.ColorDesc,
`egl_inv`.Size, `egl_inv`.GscSku, `egl_inv`.UPC,
`egl_inv`.RedistributionFlag, `egl_inv`.Date_Soldout, `egl_inv`.GGS,
`egl_inv`.Core, `egl_inv`.CartonQty,
If(IsNull(`ga_inv`.SumOfQty]=True),0,`ga_inv`.SumOfQty),
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True),
0,`ga_wip_due_within_one_week`..SumOfQty_Size_Open),
If(IsNull(`ga_wip_due_within_one_week`.SumOfQty_Size_Open=True)
,0,`ga_wip_due_within_one_week`.SumOfQty_Size),
If(IsNull(`averageweeklyfcst`=True),0,`averageweeklyfcst`),
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`),
If(IsNull(`openorder`.OpenOrders=True),0,`openorder`.OpenOrders),
If(IsNull(`egl_inv`.`SumOfQty`=True),0,`egl_inv`.`SumOfQty`),
If(IsNull(`averageweeklyfcst`.Demand=True),0,`averageweeklyfcst`.`Demand`);
The database reported a syntax error. Not unique table/alias: 'ga_wip_due_within_one_week'
You have in the middle following line
LEFT JOIN `ga_wip_due_within_one_week` ON `egl_inv`.GscSku =
`ga_wip_due_within_one_week`.GscSku) LEFT JOIN `ga_wip_due_within_one_week`
as you see you add both without an aliais for the second ad something like as
ga_wip_due_within_one_week_1 for the second

MS Access: Join on three tables with condition

In an MS Access database I try to make a join on three tables with conditions.
My current approach does not work:
SELECT
P.[COL1],
P.[COL2],
P.[COL3],
P.[COL4],
P.[COL5],
P.[PRGUID],
P.[COL6],
P.[COL7],
ARTIKEL.[COL1],
ARTIKEL.[NUMBER],
P.[PST_NR],
RECHNUNGEN.[RG_STORNO]
FROM P, A, R
WHERE R.[TIMEST] > #{from:yyyy-MM-dd HH:mm:ss}#
AND R.[TIMEST] < #{until:yyyy-MM-dd HH:mm:ss}#
AND A.[NUMBER] = VAL(P.[PLUX])
AND R.[RGUID] = P.[PRGUID] "
;
because the datasets in table P that do not have a corresponding entry in table A (condition: A.[NUMMER] = VAL(P.[PLUX])) are not returned.
I tried an approach with JOIN but I cannot find the right syntax.
Thank you #Gustav
The GUI designer helped (didn't even know it is there - just used SQL so far).
SELECT P.ColumnX, A.ColumnY, R.ColumnZ
FROM (P LEFT OUTER JOIN A.[NUMBER]) = VAL(P.[PLUX]))
INNER JOIN R ON P.[PRGUID] = R.[RGUID]
WHERE R.[TIMEST] > #yyyy-MM-dd HH:mm:ss#
AND R.[TIMEST] < #yyyy-MM-dd HH:mm:ss#

unknown class: Fixnum Rails MySQL query - inserting variable breaks my search

I had a query which was working just fine:
#schedule = Schedule.find(params[:id])
#schedule_tasks = ScheduleTask.select("s.*, t.*, t.*, d.*, st.*").from("schedule_tasks st").
joins("left join schedules s ON s.id = st.schedule_id").
joins("left join tasks t ON t.id = st.task_id").
joins("right join days d ON d.id = st.day_id").
order("d.number, t.name").
group_by{|d| d.number}
I had to refine my search to only schedule_tasks with a specific schedule_id, so I edited the second line to:
joins("left join schedules s ON s.id = st.schedule_id AND s.id = ?", #schedule.id).
This has cause the following error:
unknown class: Fixnum
The error goes away if I take out the group_by - but I need that, and I have tried hard coding in the number instead of #schedule.id and that does not work either, a google search does not reveal a lot of details on this error.
For anyone coming here from Google, I used plain string interpolation to fix this issue. This method is vulnerable to SQL Injection, so make sure you type check your variables before using them.
In this case I would do
#schedule_id = #schedule.id
.
.
.
joins("left join schedules s ON s.id = st.schedule_id AND s.id = #{#schedule_id}")
Rather than following learning_to_swim's answer, which as noted is at risk of SQL injection, couldn't you cast your #schedule_id to a string?
#tasks = ScheduleTask.joins("left join [...] s.id = ?", #schedule.id.to_s)

Unusual SQL Server Query Result

I faced with an unusual query result while running a sql server query.
The important table to note is Code_Structure_Type.
It contains columns Code_Structure_Type_Id smallint, Name char(50) and few other columns that are not used here.
My Query
SELECT DISTINCT A1.A1_Id AS Code_Unit_Attribute_Id,
A1.Name AS Code_Unit_Attribute_Name,
Code_Structure_Type.A1_Name AS Code_Attribute_Type
--, Code_Structure_Type.Code_Structure_Type_Id
FROM Defect
INNER JOIN Defect_Code_Unit
ON Defect.Defect_Id = Defect_Code_Unit.Defect_Id
INNER JOIN Code_Unit
ON Defect_Code_Unit.Code_Unit_Id = Code_Unit.Code_Unit_Id
INNER JOIN A1
ON Code_Unit.A1_Id = A1.A1_Id
INNER JOIN ERA_Module
ON Defect.ERA_Module_Id = ERA_Module.ERA_Module_Id
INNER JOIN Code_Unit_Type
ON Code_Unit.Code_Unit_Type_Id = Code_Unit_Type.Code_Unit_Type_Id
INNER JOIN Code_Structure_Type
ON Code_Unit_Type.Code_Structure_Type_Id = Code_Structure_Type.Code_Structure_Type_Id
WHERE ERA_Module.ERA_Project_Id = 472
AND ERA_Module.Is_Active = 1
AND Defect.Is_Closed = 0
AND Defect_Code_Unit.Is_Active = 1
AND Code_Structure_Type.Name = 'Pega Rules'
--AND Code_Structure_Type.Code_Structure_Type_Id = 2
AND A1.A1_Id > 0
AND Code_Unit.Scope_Id = 1
This query returns me with a single row which is incorrent. The expected result of this query should be none because we do not have Defects for 'Pega Rules' Code_Structure_Type.
If I uncomment this line
--, Code_Structure_Type.Code_Structure_Type_Id
I get no results which is correct.
Also if I filter from the Code_Structure_Type_Id which is for 'Pega Rules' not with Code_Structure_Type.Name I get the correct result as well which is none.
To do this I uncomment this line
--AND Code_Structure_Type.Code_Structure_Type_Id = 2
and comment this line
AND Code_Structure_Type.Name = 'Pega Rules'
So basically I'm doing the same thing and there is no other name like 'Pega Rules' in the table Code_Structure_Type, not even close. Only five rows are there in that table.
I need to understand what is happening here.
Thanks in advance.
Links to Execution Plans
Files, when used 'pega rules' only - incorrect_original.xml when used 'pega rules' + select - correct_with_added_select.xml when used id - correct_with_Id.xml