'Alias' And 'Order By' Troubles With Union Query?

May 10, 2007

Hello all,

Does anyone know (and would be willing to share) how one can order the results of a Union query in Access by something other than the returned values?

I have a simple Union query that would work perfectly - if I could get the thing to order the results in a particular order everytime:mad:. The query returns counts (all from one table) of separate select statements that each meet certain conditions (e.g. having state=Nevada, having state=California, etc.) as records - but since Union queries in Access order results in ascending or descending order by returned value, it puts my records in a different order every time the record values change. I need to have them ordered the same way (in the same order as they appear in the Union query, if possible) everytime so that I can return those values to specific cells in MS Excel. Any suggestions would be much appreciated!

View Replies


ADVERTISEMENT

ORDER BY (alias) Not Working...

Nov 26, 2003

rsQuery.Open "SELECT colorDepth, COUNT(*) AS colorDepthCount FROM px_users GROUP BY colorDepth ORDER BY colorDepthCount, colorDepth", dcnDB, 1, 3

returns the following error:

No value given for one or more required parameters.

Is this just an Access thing, where it won't order by an alias?

View 5 Replies View Related

Queries :: Union Query Ruins Numbered Order?

Jan 19, 2015

I have a union query with 2 fields: Order and Row_Heading_Full.

Code:

SELECT DummyClientType.Order, DummyClientType.Client_Type AS Row_Heading_Full
FROM DummyClientType
UNION SELECT ("25") AS [Order], ("Totals") AS Row_Heading_Full
FROM DummyClientType;

The purpose is to pull the Order and Row_Heading_Full fields from a table and add another entry that with "25" as the Order and "Totals" as the Row_Heading_Full at the end of the list.

I want it to be ordered sequentially based on the Order field. But instead it is ordered like this: 1, 10, 11, 12... 20, 21, 22... 3, 4, 5... In other words it is ordering only by the first digit and not by the number as a whole.

When I remove the union aspect it is ordered properly:

Code:

SELECT DummyClientType.Order, DummyClientType.Client_Type AS Row_Heading_Full
FROM DummyClientType;

But that defeats the purpose because I am not adding a final entry of "25" and "Totals".

View 14 Replies View Related

Do Fields Have To Be In Same Order For A Union?

Mar 6, 2014

I have some tables with identical field names, but the fields are in a different order. Is it possible to do a union like this, or do I have to rearrange the data within each table first?

For instance:

Table A: Field1, Field4, Field2, Field3
Table B: Field3, Field1, Field4, Field2
Table C: Field2, Field3, Field1, Field4

And I'm trying to combine those tables into TableABC: Field1, Field2, Field3, Field4.

View 3 Replies View Related

Queries :: UNION / UNION ALL Query Crashed Access

Oct 24, 2013

I'm having a problem with a UNION / UNION ALL query.It seems there is a application crash fault when running the query that MS are aware of and have issued a hot fix. Unfortunately it will take my IT dept some time to check and install the hot fix If they agree to do it at all.

Problem signature:
Problem Event Name: APPCRASH
Application Name: MSACCESS.EXE
Application Version: 12.0.6606.1000

[code]...

View 1 Replies View Related

Query Troubles (DuplicateDate)

Jan 4, 2006

Hi all,

I have a query that returned multiple duplicates of a record (3 or more) between a specified start date and end date (entered by the operator) and displays them into a report. I created the query using the duplicate wizard and changed >1 to >=3 and added "AND ((Guardcalloutsarchive.Date) Between [Start Date] And [End Date]))" to promoted operator to enter date range.

The problem is I only want the query to give me multiple duplicates from within the specified date range only. The query is returning multiple duplicates form the entire table.

Any input would be appreciated.

View 2 Replies View Related

Alias Woes

Sep 25, 2007

so, I have created a working SQL statement that summarises data from a bunch of different tables (it's a stock monitoring application so it all has to do with levels of stock, numbers of parts processed etc...):

SELECT tblPPIn.BatchID,
tblPartDescriptions.DrawingNumber AS [Drawing Number],
tblOrder.IssueNumber AS [Issue Number],
tblPartDescriptions.Description AS [Description],
tblPPIn.Qty AS [Total Booked In],
IIf(IsNull((SELECT Sum(tblPPProcessed.QtyProcessed) AS SumOfQtyProcessed FROM tblPPProcessed WHERE tblPPProcessed.BatchID = tblPPIn.BatchID;)),'0',(SELECT Sum(tblPPProcessed.QtyProcessed) AS SumOfQtyProcessed FROM tblPPProcessed WHERE tblPPProcessed.BatchID = tblPPIn.BatchID;)) AS [Total Qty Processed],
IIf(IsNull((SELECT Sum(tblPPOut.Qty) As sumofQtyOutPass FROM tblPPOut WHERE tblPPOut.BatchID = tblPPIn.BatchID AND tblPPOut.IQCPass = 'PASS';)),'0',(SELECT Sum(tblPPOut.Qty) As sumofQtyOutPass FROM tblPPOut WHERE tblPPOut.BatchID = tblPPIn.BatchID AND tblPPOut.IQCPass = 'PASS';)) AS [Total Good Parts Taken],
IIf(IsNull((SELECT Sum(tblPPOut.Qty) As sumofQtyOutUninspected FROM tblPPOut WHERE tblPPOut.BatchID = tblPPIn.BatchID AND tblPPOut.IQCPass = 'UNINSPECTED';)),'0',(SELECT Sum(tblPPOut.Qty) As sumofQtyOutUninspected FROM tblPPOut WHERE tblPPOut.BatchID = tblPPIn.BatchID AND tblPPOut.IQCPass = 'UNINSPECTED';)) AS [Total Uninspected Parts Taken],
IIf(IsNull((SELECT Sum(tblPPProcessed.QtyPass) AS SumOfQtyPass FROM tblPPProcessed WHERE tblPPProcessed.BatchID = tblPPIn.BatchID;)),'0',(SELECT Sum(tblPPProcessed.QtyPass) AS SumOfQtyPass FROM tblPPProcessed WHERE tblPPProcessed.BatchID = tblPPIn.BatchID;)) AS [Total Passes],
IIf(IsNull((SELECT Sum(tblPPProcessed.QtyFailEtching) + Sum(tblPPProcessed.QtyFailCutOut) + Sum(tblPPProcessed.QtyFailFlatness) + Sum(tblPPProcessed.QtyFailHandling) + Sum(tblPPProcessed.QtyFailOther) AS SumofFails FROM tblPPProcessed WHERE tblPPProcessed.BatchID = tblPPIn.BatchID;)),'0',((SELECT Sum(tblPPProcessed.QtyFailEtching) + Sum(tblPPProcessed.QtyFailCutOut) + Sum(tblPPProcessed.QtyFailFlatness) + Sum(tblPPProcessed.QtyFailHandling) + Sum(tblPPProcessed.QtyFailOther) AS SumofFails FROM tblPPProcessed WHERE tblPPProcessed.BatchID = tblPPIn.BatchID;))) AS [Total Fails],
[Total Booked In]-[Total Qty Processed]-[Total Uninspected Parts Taken] AS [Total Unprocessed Parts Remaining],
[Total Passes]-[Total Good Parts Taken] AS [Total Good Parts Remaining],
[Total Passes]/[Total Qty Processed] AS [Overall Yield]
FROM tblPPIn INNER JOIN (tblPartDescriptions INNER JOIN tblOrder ON tblPartDescriptions.DrawingNumber = tblOrder.DrawingNumber) ON tblPPIn.BatchID = tblOrder.BatchID
ORDER BY tblPPIn.BatchID ASC;

don't worry about the details, it works as it is above...

now I only want to display data for batches where there are some parts left, so I've tried adding the following WHERE clause:

WHERE ([Total Good Parts Remaining] + [Total Unprocessed Parts Remaining]) <> 0

should work fine, right?
nope, we get the (all too familiar) 'Enter parameter value: Total Good Parts Remaining' (and the same for 'Total Unprocessed Parts Remaining'), despite the fact I have used these aliases in the previous SQL with no problem...

Is there any way around this or do I have to create a big-ass WHERE statement complete with the subqueries I've already used previously?

This is seriously annoying me today... any help would be massively appreciated!

cheers,
Bogzla

View 7 Replies View Related

ODBC Link With Alias Name...

Sep 27, 2005

I am trying to use one Access 97 mdb file to attach to two different SQL servers depending on the situation, one is production the other is a backup server. (The application requires an Access97 file format so I can't change that) I have a DNS Alias for the server name and I put that in the ODBC under Server Name. When I have the Alias changed from Production to Backup I want the Access file to see the data on the backup box.

It appears that MSAccess stores the Server name when the link is made in the MSysObject.Connect field and it does not update that even, if the ODBC is changed. I have one test connection that seems to working because I created it using the ODBC after the Alias was added. The string it puts in the connect field has no reference to the server name or address similar to what is below.

DSN=A_C;Description=A Control;UID=username;APP=Microsoft® Access;WSID=PC22361;DATABASE=DACSP001;Trusted_Conn ection=Yes

The MSysObject.Connect in a file that did not use the Alias looks like this...

DSN=A_C;Description=A ;APP=Microsoft® Access;WSID=PC27368;DATABASE=DACSP001;Network=DBMS SOCN;Address=pmnt9511.sce.corp.com,1433

So I think I need to recreate a new file using the Alias in the ODBC so the specific address is not in the connection string. What do you think?
Has anyone used an Alias name like I am trying to switch between like databases on two different servers? It seems weird that in the first example above there is not reference to the alias name so maybe this forces it to look it up.

Thanks in advance...

View 1 Replies View Related

Queries :: IIF Statement Expression - Create Alias Column Based On Data From Two Fields

Jun 20, 2013

I am writing a very complex 'if statement' query expression. I need to create an alias column based on data from two data fields.

Here's the logic:

True: If [PP] = "WG" or "WS" or "WL" and If [GR] > 10 Then "Skilled" or
[GR] Between 6-9 Then "Semi - Skilled" or [GR] <6 Then "Unskilled"

False: "GS"

View 2 Replies View Related

UNION Query MS Jet Database Engine Cannot Find The Input Table Or Query.

Oct 28, 2005

Hello All,

I'm trying to run a UNION query that joins five queries through a MS WorkSpace into a DAO.recordset in VB. I'm pulling the data from a SQL Server Database through VB in Access. I'm attempting to open a recordset with a query passed to it as a string. The query is below. For some reason, I'm receiving a message: "MS Jet database engine cannot find the input table or query. Runtime Error 3078".

Here's what's puzzling. When I run a single query without any UNION statement, the code finds the table and runs fine without error, but anytime I join two or more queries with a UNION statement in the VB, it gives me the error.

I've executed the same UNION query in both Access Query Builder and SQL Server's Query Analyzer and they work fine in both environments. It's only when I call the query from a DAO.Recodset with VB that it causes this problem. The following is a sample of the UNION query joining two of the five queries. Does anyone have any idea what could be the problem? The following query executes in about 5 seconds so I don't think there's a "time-out" issue. I'm thinking that the UNION statement may be the culprit. Maybe there's another way to approach joining these separate queries? Any help would be most appreciated. Thanks.

SELECT SalespersonID, Sum([SlsPrice]-[RtnPrice]-[SlsDiscnt]+[RtnDiscnt]) AS fldPrice FROM MyTable WHERE (((Source)='d') AND ((DistrictID)='01') AND ((CategoryID) = 'HCPROD') AND ((BrandID)<>'CSS')) AND (((BrandID)<>'1356')) AND (((BrandID)<>'1400')) AND (((BrandID)<>'1551')) AND (((BrandID)<>'555')) AND (((BrandID)<>'66'))
AND (TransDate >= 07/01/2005) AND (TransDate <= 07/31/2005) GROUP BY SalespersonID
UNION
SELECT SalespersonID, Sum([SlsPrice]-[RtnPrice]-[SlsDiscnt]+[RtnDiscnt]) AS fldPrice FROM MyTable WHERE (((Source)='d') AND ((DistrictID)='01') AND ((ProductID) = '0029800')) AND (TransDate >= 07/01/2005) AND (TransDate <= 07/31/2005) GROUP BY SalespersonID

Set wrkJet = CreateWorkspace("", "pw", "", dbUseJet)
Set db = wrkJet.OpenDatabase("DW", _
dbDriverNoPrompt, True, _
"ODBC;DATABASE=DW;DSN=DW2")
'Set rs1 = db.OpenRecordset(strSQL)

View 9 Replies View Related

Report Troubles

Jan 17, 2007

First off, thanks to all who have helped me with my other posts :)

I have yet another question that y'all might be able to assist me with... I'm looking to create a report and am having trouble figuring out how exactly to format the stupid thing... And, like my other posts, this could be a little confusing... I'll do my best ;)

I've modified this a bit to figure one thing out at a time. If you have a solution to my original post (below) feel free to help out, but for now I am just trying to figure out how to get the variables in the report to go across the page instead of down. I would like my quantity field to be listed across the page with the price for the part below it:

1-9 10-24 ... 50K+
$$ $$ $$

instead of:

1-9
$$

10-24
$$

...

50000+
$$

Thanks!


------ Here's my original post------
Ok, I've already got a query with all the data and computations needed. Basically I'm just trying to create a price sheet for our products here, but it's not quite that simple... I have 72 different part sizes, 12 for each of 6 voltages (3KV, 5KV...20KV), and a price for 13 different qty ranges (1-9, 10-24...50000+). I would like it to look something like this:

Qty1-9 Qty10-24 ... 50K+
Part 1 $$ $$ $$ $$
Part 2 $$ $$ $$ $$
Part 3 $$ $$ $$ $$
Part 4 $$ $$ $$ $$
Part 5 $$ $$ $$ $$
Part 6 $$ $$ $$ $$
Part 7 $$ $$ $$ $$
Part 8 $$ $$ $$ $$
Part 9 $$ $$ $$ $$
Part 10 $$ $$ $$ $$
Part 11 $$ $$ $$ $$
Part 12 $$ $$ $$ $$
...
Part 72 $$ $$ $$ $$

Parts 1-12 will be grouped by Voltage 1, Parts 13-24 by Voltage 2, and so on... Have I lost you yet? :confused: :confused: :confused:

Grouping by voltage can be left out for now if it add too much confusion...

View 2 Replies View Related

Icon Troubles

Aug 19, 2007

Hi, this is my first message on this forum ;)!
I have a little problem with my Access 2000 (with 2003 too on another compuer), in fact when I put an icon on a page of my Tab Control, the background of that icon is white and not transparent (the file I use is an "ico" file and so it HAS a transparent background, anyway I treid all the possible file types); the strange thing is that when I put an icon on a button, the icon is shown properly. Here is an image of my problem:

http://img529.imageshack.us/img529/9922/testuu9.jpg

Thank you,

StockBreak

View 10 Replies View Related

Relationship Troubles

Feb 29, 2008

here is what i have:

tables - tblAssets, tblSites, tblManufacturers, tblModels

i have 1-to-many relationships set up as follows; tblManufacturers --> tblAssets, tblManufacturers --> tblModels, tblModels --> tblAssets, tblSites --> tblAssets.

what i would like to happen is if i add a new site in tblAssets it will add the site in tblSites as well. if i have "enforce referential integrity" checked then it will only let me insert sites that are on the tblSites table, and if i uncheck the box then it will allow me to put in a site that's not on the table, but it doesn't add it to the table.

i only have 1 form and it's just linked to the tblAssets table. please forgive my noobness, i've been having a rough time trying to understand relationships even though i've read about everything i could find on them, so could someone please point me in the right direction?

thanks

View 8 Replies View Related

Help!! Autofill Troubles

Dec 1, 2005

I created a form from a table (maintbl) with a combo box. The combo box retreives information from another table (model#tbl)and autofills it in the fields below. the information that is autofilled does not automatically get entered into maintbl. Theres probably a good reason for this but i cant figure it out. Anyone?? Im not very good with code but if thats what it takes thats what it takes.

View 2 Replies View Related

Totalling Troubles- Help!

Apr 4, 2005

Hi,

I have hit a brick wall with my A-Level Access Project. Basically, I have a form for ordering where a user can select items from a combo box linked to a table that contains products. They then select the quantity and a subtotal is calculated for that particular item(s). By that I mean the subtotal generated is only for one selection from the combo box. Any subsequent selections have their own subtotals generated afterwards (I hope I'm not being too vague).
This is the form I am talking about:
http://img.photobucket.com/albums/v318/GOAT2G/FrmMakeOrder1.jpg

The thing I am having trouble with is the final box; "Order Total". I have no idea how to set it to sum all of the above Subtotals to equal an overall total. I will send anyone willing to help a copy of the database via email or something if they need it.

I would be immensely grateful for any help you can give.

Thanks,
Adam

View 5 Replies View Related

Date Troubles

Feb 19, 2006

Hi

I have just started using access to design Data entry screens for our SAS databases.

One of our major fields in our databases is an update date field which is set up in this format 20062002. year day month.

Now I am trying to make a text box on our form that displays the date like this.

I know i can do =year(date()) to show the year but I cant work out how i can get it to display year, day month in that format.

Any help would be much appreciated.

View 1 Replies View Related

Combo Box Troubles!

Oct 26, 2006

Hi,

Im currently making my first database for a company i work for. As expected im having some troubles hehe im not sure im going about everything the right way. At the moment im trying to create a form which will get product information from one table, display the details in a few combo boxes and based on a selection will store the selections in a separate table. Ive done everything up till that last bit, i cant seem to be able to record the selections in a separate table.

i would appreciate some help as my bosses have to be kept up to speed on my progress and as you can imagine it doesnt look so good when you tell them you havent made any progress hehe.

Cheers

Marc.

View 4 Replies View Related

Subform Troubles...

Jun 16, 2007

I have a form that I'm trying to make a sub-form for. I create the sub-form and link the two forms by a text field, but for some reason instead of being the contents of the field that links them being the same, it's the name of the Form, and thus any time I refresh the page the subform data gets lost in the table and is unassociated with any records I have on the main form...

I've done subforms before without a problem, so why are they messing up for me now?

View 7 Replies View Related

SQL Union Query

Aug 18, 2005

I have created a report that provides me with employee expenses for temps per week. The types of expenses have been defined as Ad_hoc amounts.

An SQL union query I have used to combine fields

Adhoc_Code_1 - 3
Adhoc_description_1 - 3
Adhoc_Pay_Amount_1 - 3

(details of full sql query below)

I have tried to run for a particular week which should have 3 expense entries but only 2 have been picked up.

I think this is because both Adhoc_ Pay_Amount_2 and 3 have a value of 6 and the UNION operation will not return duplicate records. I have amended to UNION ALL but all entries are duplicated. Can anyone help?

Thanks

SELECT dbo_Valid_Timesheets.Employer_Ref, dbo_Valid_Timesheets.Personnel_Ref, dbo_Valid_Timesheets.Department, dbo_Valid_Timesheets.Tax_Yr_Proc_By_Payroll, dbo_Valid_Timesheets.Period_Proc_By_Payroll, dbo_Valid_Timesheets.Session_Proc_By_Payroll, dbo_Valid_Timesheets.Adhoc_Code_1, dbo_Valid_Timesheets.Adhoc_Description_1, dbo_Valid_Timesheets.Adhoc_Pay_Amount_1, dbo_Valid_Timesheets.Timesheet_Number
FROM dbo_Valid_Timesheets
WHERE (((dbo_Valid_Timesheets.Adhoc_Pay_Amount_1)<>0));
UNION ALL
SELECT dbo_Valid_Timesheets.Employer_Ref, dbo_Valid_Timesheets.Personnel_Ref, dbo_Valid_Timesheets.Department, dbo_Valid_Timesheets.Tax_Yr_Proc_By_Payroll, dbo_Valid_Timesheets.Period_Proc_By_Payroll, dbo_Valid_Timesheets.Session_Proc_By_Payroll, dbo_Valid_Timesheets.Adhoc_Code_2, dbo_Valid_Timesheets.Adhoc_Description_2, dbo_Valid_Timesheets.Adhoc_Pay_Amount_2, dbo_Valid_Timesheets.Timesheet_Number
FROM dbo_Valid_Timesheets
WHERE (((dbo_Valid_Timesheets.Adhoc_Pay_Amount_2)<>0));
UNION ALL
SELECT dbo_Valid_Timesheets.Employer_Ref, dbo_Valid_Timesheets.Personnel_Ref, dbo_Valid_Timesheets.Department, dbo_Valid_Timesheets.Tax_Yr_Proc_By_Payroll, dbo_Valid_Timesheets.Period_Proc_By_Payroll, dbo_Valid_Timesheets.Session_Proc_By_Payroll, dbo_Valid_Timesheets.Adhoc_Code_3, dbo_Valid_Timesheets.Adhoc_Description_3, dbo_Valid_Timesheets.Adhoc_Pay_Amount_3, dbo_Valid_Timesheets.Timesheet_Number
FROM dbo_Valid_Timesheets
WHERE (((dbo_Valid_Timesheets.Adhoc_Pay_Amount_3)<>0));

UNION ALL SELECT dbo_EE_Payment_History.Employer_Ref, dbo_EE_Payment_History.Personnel_Ref, dbo_Payslip_Static_Data.Department, dbo_EE_Payment_History.Tax_Year, dbo_EE_Payment_History.Tax_Period, dbo_EE_Payment_History.Tax_Session, dbo_EE_Payment_History.Payment_Ref, dbo_EE_Payment_History.Type, Val([Payment_Value]) AS [Value], "" AS Timesheet
FROM dbo_EE_Payment_History INNER JOIN dbo_Payslip_Static_Data ON (dbo_EE_Payment_History.Tax_Session = dbo_Payslip_Static_Data.Session_Number) AND (dbo_EE_Payment_History.Tax_Period = dbo_Payslip_Static_Data.Period_Number) AND (dbo_EE_Payment_History.Tax_Year = dbo_Payslip_Static_Data.Tax_Year) AND (dbo_EE_Payment_History.Personnel_Ref = dbo_Payslip_Static_Data.Personnel_Ref) AND (dbo_EE_Payment_History.Employer_Ref = dbo_Payslip_Static_Data.Employer_Ref)
WHERE (((dbo_EE_Payment_History.Tax_Year)=[Forms]![Misc]![year]) AND ((dbo_EE_Payment_History.Tax_Period)=[Forms]![Misc]![period]) AND ((dbo_EE_Payment_History.Tax_Session)=[Forms]![Misc]![session]) AND ((dbo_EE_Payment_History.Payment_Ref)=777));

UNION ALL SELECT dbo_EE_Payments.Employer_Ref, dbo_EE_Payments.Personnel_Ref, dbo_Payslip_Static_Data.Department, [Forms]![Misc]![year] AS Tax_Year, [Forms]![Misc]![period] AS Tax_Period, [Forms]![Misc]![session] AS Tax_Session, dbo_EE_Payments.Payment_Ref, dbo_EE_Payments.X_Type, Val([Calculated_Value]) AS [Value], "" AS Timesheet
FROM dbo_EE_Payments INNER JOIN dbo_Payslip_Static_Data ON (dbo_EE_Payments.Personnel_Ref = dbo_Payslip_Static_Data.Personnel_Ref) AND (dbo_EE_Payments.Employer_Ref = dbo_Payslip_Static_Data.Employer_Ref)
WHERE (((dbo_EE_Payments.Payment_Ref)=777));

View 10 Replies View Related

UNION ALL Query

May 19, 2005

OK, so I am UNIONing two tables using UNION ALL. It works fine. The resultant table has 192 records (63 + 129).

If a use just UNION or UNION DISTINCT I get 184 records. I'm pretty sure that is telling me that 8 records (192 - 184) exist in both tables.

How do I query to find out what those 8 records are?? I'm trying to use an INTERSECT in MS Access, but it doesn't want to work. Here is my original query:

select * from qryMOE_Active_All
UNION ALL select * from qryMOE_Closed_All;

Thanks,

Brian

View 3 Replies View Related

Union Query

Sep 26, 2005

I am a basic access user so please forgive my ignorance. I have created a union query of three tables. There is one field from the third table that I would like to have in the final table but this field does not exist in the first table. If I put "none" in the first SELECT line, then it queries correctly but the field name on the table is "Expr1006". If I put "Field 2" or [Field 2] in that same space of the first SELECT line, then it asks me for a parameter value and whatever I enter it fills in all the cells of that field with that value. I just don't know that language very well or even if you can add a new field into the first SELECT table. Thank you for any thoughts

Ex: SELECT [Field 1], [Field 2], "none", [Field 3]
FROm [Table 1]
UNION
SELECT [Field 1], "none", [Field 2], [Field 3]
FROM [Table 2]

View 3 Replies View Related

Union All Query Help

Mar 16, 2006

Hello All,
I need help with an Union All Query. It is ignoring the second select statement. Can anyone see what I am doing wrong?

SELECT
CEPM_PLGR.COST_ELEM_CTGY AS [COST_ELEM_CTGY]
, CEPM_PLGR.PROJ_ELEM_ID AS [PROJ_ELEM_ID]
, CEPM_PLGR.COST_ELEM AS [COST_ELEM]
, CEPM_PLGR.SUM_UNIT AS [SUM_UNIT]
, CEPM_PLGR.PRD AS [PRD]
, CEPM_PLGR.CUR_BUD AS [CUR_BUD]
, CEPM_PLGR.PRD_BUD AS [PRD_BUD]
, CEPM_PLGR.CURRENT_ACT AS [CURRENT_ACT]
, CEPM_PLGR.PERIOD_ACT AS [PERIOD_ACT]
, CSIOWNER_PELM.PROJ_ELEM_DESC AS [PROJ_ELEM_DESC]
, CSIOWNER_PELM.PROJ_ELEM_MGR AS [PROJ_ELEM_MGR]
, CSIOWNER_PELM.PROJ_ELEM_TYPE AS [PROJ_ELEM_TYPE]
, NULL AS [COMMIT GA]
, CSIOWNER_PELM.COST_STAT AS [COST_STAT]
, CSIOWNER_PELM.PROJ_NBR AS [PROJ_NBR]
,NULL AS [COMMIT $]
FROM
CEPM_PLGR INNER JOIN CSIOWNER_PELM ON CEPM_PLGR.PROJ_ELEM_ID = CSIOWNER_PELM.PROJ_ELEM_ID
WHERE
((CSIOWNER_PELM.PROJ_TYPE)<>"T&M" And (CSIOWNER_PELM.PROJ_TYPE)<>"T7M") AND ((CSIOWNER_PELM.COST_MODE)="D")
AND ((CEPM_PLGR.PROJ_ELEM_ID)<>" ")
UNION ALL SELECT
NULL AS [COST_ELEM_CTGY]
, NULL AS [PROJ_ELEM_ID]
, NULL AS [COST_ELEM]
, NULL AS [SUM_UNIT]
, NULL AS [PRD]
, NULL AS [CUR_BUD]
, NULL AS [PRD_BUD]
, NULL AS [CURRENT_ACT]
, NULL AS [PERIOD_ACT]
, NULL AS [PROJ_ELEM_DESC]
, NULL AS [PROJ_ELEM_MGR]
, NULL AS [PROJ_ELEM_TYPE]
, (IIf( [PROJECT ID] Like "N0160*" And "N8100*" And "N9004*"
,(NZ([COMMIT $],0))
,(NZ([COMMIT GA $],0)))) AS [COMMIT GA]
, NULL AS [COST_STAT]
, NULL AS [PROJ_NBR]
, [PURCHASE_COMMITMENTS_FINAL].[COMMIT $] AS [COMMIT $]
FROM
[PURCHASE_COMMITMENTS_FINAL]
WHERE [PURCHASE_COMMITMENTS_FINAL].[PROJECT ID]
IN
(SELECT CEPM_PLGR.PROJ_ELEM_ID AS [PROJ_ELEM_ID]
FROM
CEPM_PLGR INNER JOIN CSIOWNER_PELM ON CEPM_PLGR.PROJ_ELEM_ID = CSIOWNER_PELM.PROJ_ELEM_ID
WHERE
((CSIOWNER_PELM.PROJ_TYPE)<>"T&M" And (CSIOWNER_PELM.PROJ_TYPE)<>"T7M") AND ((CSIOWNER_PELM.COST_MODE)="D")
AND ((CEPM_PLGR.PROJ_ELEM_ID)<>" ")) AND (([PURCHASE_COMMITMENTS_FINAL].[PROJECT ID]) <> " ");

I think it is my where clause IN function. But I do not know how to fix it. any help would be great!!!!
Thanks in advanced, Kerrie

View 2 Replies View Related

Union Query

Aug 3, 2006

Okay, people. I am getting married in a few days and my mind is on other things. Consequently, I can't get my head around this one.

I have two queries, Query1 and Query2. Both have a different number of fields but they have the field "IA Code" in common.

I want to create a new query containing all rows from Query1 and all rows from Query2. Where the [IA Code] matches, I'd like the information to be displayed in one row.

I think I need to use Union somewhere along the lines, but I can't work it out.

Any pointers/syntax greatly appreciated.

View 1 Replies View Related

Union Query Help Please

Jan 25, 2007

I have 2 tables with employee details in it. There is no natural link between the 2. I wish to write a query that will sum up the total pay for both tables.

I've had a look through the forum and it seems that a Union query is probably best.

I haven't worked with Unions before, so I did 2 sub queries to total the pay in both table and then union the 2 queries. I did this because there are some date parameters that I query each table by so I do this in the sub queries.

This works but I get 2 outputs in the result, the total pay from each table. I wanted to have just one output, which is the sum of all pay.

Can anyone help please.

SQL:
SELECT QrySub_TotalPay1.TotalPay 'sub query that sums up table 1
FROM QrySub_TotalPay1
UNION SELECT QrySub_TotalPay2.TotalPay 'sub query that sums up table 2
FROM QrySub_TotalPay2;

TIA.

View 3 Replies View Related

Union Query Help

Apr 24, 2007

I have 2 tables and I m trying to get sum of qty for each product
I tried union qurey following way but doesn't work.

Product_Master table has primary key set up on productcode. I need to pick up OpeningBal along with ProductName and ProductCode from this table.

T_PurInvFoot table contains multiple records of the similar ProductCode. I want to make sum of these PurQty data and add it with OpeningBal data from Product_master table and present it in one line.

The avalable quanities are in 2 diff. tables are here.

Product_Master.OpeningBal=5
(1 Record)

T_PurInvFoot.PurQty =4
T_PurInvFoot.PurQty =6
(2 Records)

So total it should be 15 when it produce records. But it show only 10 records from below query.

SELECT Product_Master.ProductCode, Product_Master.ProductName,Sum(Product_Master.Open ingBal) as Stock
From Product_Master INNER JOIN T_PurInvFoot ON T_PurInvFoot.ProductCode=Product_Master.ProductCod e
Group By Product_Master.ProductCode,Product_Master.ProductN ame

UNION Select T_PurInvFoot.ProductCode, T_PurInvFoot.ProductName, sum(T_PurInvFoot.PurQty) as Stock
From T_PurInvFoot INNER JOIN Product_Master ON T_PurInvFoot.ProductCode=Product_Master.ProductCod e
Group By T_PurInvFoot.ProductCode,T_PurInvFoot.ProductName
ORDER BY Product_Master.ProductCode;

Can somebody advice me how to do it.

I need to add 3rd table here in future to get sum of the qty of the similar ProductCode so how to the query would be?

One more thing, can we do it in VBA and set the RecordSource to a form or report ?

With kind regards,
Ashfaque

View 1 Replies View Related

Union Query??

Oct 11, 2007

Hello All,

What I am trying to do is if the field (CAR) or (PAR) or (Incident) is checked in this table (Inventory Worksheet) then show it. I not sure how to use the union query to accomplish this.

Any Ideas?

Thanks,

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved