Queries :: Using SQL Inside IN Condition For Parameters?

May 29, 2015

I have a sql to run and I have to use many values as parameters (over 1000), which is why I am trying to use a SQL inside a IN condition.

I am testing the sql with only 1 value for now. The parameter I am using will be 2208287. This returns in a matter of seconds.

Code:
Select a.po_id, a.sku12, sum(a.unit) AS Units, sum(a.weighted) AS Weighted_Units, ((sum(a.weighted))/ (sum(a.unit))) AS weighted_turntime
From(
SELECT ds.src_evnt_txn_tmst AS alloc_ts, bc.src_evnt_txn_tmst AS ship_ts, ds.Po_id, Left(bc.sku16,12) AS SKU12, ds.distro_id AS alloc_distro, bc.distro_id AS Ship_distro, Sum(bc.unit_qty) AS Unit,

[Code] .....

but it does not work when I add a sql inside the IN condition. It actually runs forever and eventually I have to break it to stop. why this is not working with a sql inside a IN condition.

Also note:

table ROSS_REPORT_DISTRO_DTLS_SUM is a linked table
table BOL_CONTNR_SKU16_RTED is a linked table
table CopyOfdata is a local table (This is where I will put all of my values to act as parameters)

Code:

Select a.po_id, a.sku12, sum(a.unit) AS Units, sum(a.weighted) AS Weighted_Units, ((sum(a.weighted))/ (sum(a.unit))) AS weighted_turntime
From(
SELECT ds.src_evnt_txn_tmst AS alloc_ts, bc.src_evnt_txn_tmst AS ship_ts, ds.Po_id, Left(bc.sku16,12)
AS SKU12, ds.distro_id AS alloc_distro, bc.distro_id

[Code] ....

View Replies


ADVERTISEMENT

Queries :: Putting Aggregate Inside A Where Clause

Oct 11, 2014

I need to change the below to a where clause to fit inside a union query that is just where clauses.

tblNEWNONTODATA.DateOfVisit) AS FirstOfDateOfVisit
FROM tblNEWNONTODATA
GROUP BY tblNEWNONTODATA.EVX, tblNEWNONTODATA.TCGDecision
HAVING (((tblNEWNONTODATA.TCGDecision)="Adopted" Or (tblNEWNONTODATA.TCGDecision)="Hot Tasked") AND ((First(tblNEWNONTODATA.DateOfVisit))>=#10/1/2014#));

View 2 Replies View Related

Queries :: Select Query Inside VBA Code?

May 21, 2013

I'm trying to create a query inside VBA code.

the problem is that my query is a select query and therefore I can't use RunSQL

I tried to work around it withbut had no luck... this is the code:

strSql = "SELECT '" & Me.number & "' ,Karin.[subject] " & "From Karin " & "WHERE '" & Me.number & "'" = done

View 12 Replies View Related

Queries :: Reading Values In CSV Text Inside A Query

May 13, 2014

I have a text field that contains a comma delimited list of numbers.

I am trying to read one of these numbers from OLEDB through to an access database.

I am trying to do the following:

SELECT SPLIT(CSVData, ValueNo) as ReturnValue FROM MyCSVDataTable

Where CSVData is a split field containing values like "123,234,345,..." and ValueNo is a value to identify which one i want.

Any way of achieving this using the standard SQL functions. I am reading the data via OleDB and therefore cannot use a user defined VBA function?

View 1 Replies View Related

Queries :: Including Record That Is Inside Excluded Range

Oct 2, 2014

Including a record that's inside an excluded range.

I have a table with record numbers from 1 to 91599. I want to exclude records from 91011 to 91599 but I don't want to exclude record 91102.

How do exclude a record that is included in the excluded range?

I could write two queries the first will excludes 91011 to 91101 and the second excludes 91103 to 91599. Is this the only way?

View 3 Replies View Related

Queries :: Like Condition Using Wildcards

Apr 5, 2013

I have a table called Coded_Data with one particular field called Codes. This field list a number and a respective code to identify what type of code it is. For instance 123456789-AD...123456789-ADS. I am wanting to create to two columns. One listing all work orders coded with AD and the other withADS. When I use the Like condition with % it returns both AD and ADS in same column. I understand why because the "%AD" returns anything that starts with AD so this is why I get both codes. I only want to get the the AD codes in one column and ADS in the other. I have duplicated the table twice since I am trying to retrieve data from the same field and table but display in 2 separate columns. The duplicated table has a different alias. The problem is in the where clause.

where (((coded_data.codes) LIKE "%AD")) or ((coded_data_1.codes) LIKE "%ADS");

View 3 Replies View Related

Queries :: Append Query Where A Condition Has To Be Met

Feb 26, 2014

I am trying to copy notes from one table to another table where a condition has to be met and I can't figure out how to do that in an APPEND query.

Each record has a unique number that comes into my Initial Table in my Access database from a construction program I download. In this particular table both the [DNJTNo] and [DNVersionNmbr] fields can have duplicate numbers. However, when I run the query I want it to add a record to the second table only after the query checks that the [DNJTNo] in combination with the [DNVersionNmbr], is not already in the table. If it is, I do NOT want it appended to the second table. (I have attached a picture of the query in APPEND design stage).

View 2 Replies View Related

Queries :: Searching Date Before And Using This In WHERE Condition

Sep 13, 2013

I have a table that has 4 fields; id_vl, id_product, date_vl, vl.

Basically each product is valued either on a monthly, weekly or daily basis. I want to create a filter that is based on a text box that filters the dates from which one can look at the dates of valuation and the associated values.

The problem comes with the products valued on a weekly or monthly basis. For example, if I simply say [tblvl].[date_vl]>=Me.textbox, and me.textbox = 13/09/2013, yet the last value date for a weekly product was 09/09/2013, this record won't be included. Therefore I need to set the date of the previous record as the filter. This is my attempt but it doesnt work...

Code:
SELECT tblVL.Id_VL, tblVL.Id_Product, tblVL.Date_VL, tblVL.VL,

FROM tblVL
WHERE iif(tblvl.date_vl<>me.fees_start_date, [tblVL].Date_VL>=(SELECT
MAX(PrevDate.Date_VL)
FROM tblVL AS PrevDate WHERE PrevDate.Date_VL<[tblVL].[Date_VL] AND PrevDate.Id_Product=tblVL.Id_Product;),tblvl.date_vl>=Me.fees_start_date)
;

View 1 Replies View Related

Queries :: Nested IIF - Not Getting Correct Value When Add Second Condition

Oct 24, 2013

I am using the IIf function as follows

Exp1:IIf(field A = "a string value",1,0) this returns the correct value.

However when I try to add a second condition using the IIf function, or use the And Or condition, I do not get the correct value.

I am trying to get a value of 1 in the Exp:Col when field B has a value that is different from field A.

What is the correct syntax? What am I missing??

View 13 Replies View Related

Queries :: IIF Condition With Incorrect Result

Dec 11, 2014

I have a POLEFFDATE field with dates in date/time format. A single record has POLEFFDATE equal to 12/15/2013. I calculated a simple field called EVALUATE as follows: IIF([POLEFFDATE]< 1/1/2014,1,0). EVALUATE should equal 1 for this record, but it equals 0. Why ?

View 3 Replies View Related

Queries :: How To Export Crosstab Queries By Date Parameters

Feb 23, 2015

How can you export cross tab queries by using date parameters (for example: Jan 1, 2014 to December 31, 2014)...

View 3 Replies View Related

Queries :: Report Or Macro To Run Multiple Queries Using Same Parameters?

Aug 9, 2013

So I run cash flow for a business, and we export data from Oracle and insert it into an access database. I have to run about 25 queries, entering in the same parameters for each. We number each week of the year. So for say the first week in January, I would run the first query and it asks: Beginning Week, I enter in 1, then another paramter value asks me the ending week. I have to enter in these parameters for each of the 25 or so queries, and it becomes quite irritating. Each query has a number of columns, but I am only interested in obtaining the sum of one of the columns, titled Distribution amount. So I am looking for something that will run each of my specified queries, then spit out the total of the distribution column for each in a table like.

Query 1: Total Distribution
Query 2: Total Distribution
etc....

Is there anything that would allow me to do this, with entering in the week parameter once, say week 1 start, week 1 end. and it use those same parameters for each query?

View 1 Replies View Related

Queries :: How To Use OR Condition In Query Builder Wizard

Aug 19, 2014

I have to three fields in my query wizard, lets call them A and B and C. The condition for the query is either A or B is Null and C is Null. Im not sure how to do this though becuase A, B and C are different fields. I wrote

Code:
Is Null

.

under the criteria of A and B and C, but this specifies that A,b and C is Null, how can I make it so that C must be Null and either A or B or Both.

View 1 Replies View Related

Queries :: Finding Unmatched Records With A Condition?

Dec 26, 2013

I want to find unmatched records, where there is a condition. Specifically, which employees did not get a specific mail.

My employees are in this table:

tblEmployees
---------------
EmployeeID (PK)
FullName (text)

and sent mails are logged in tblMailsSent

tblMailsSent
--------
MailID (FK)
EmployeeID (FK)

so I want to find all the employees in tblEmployees whose EmployeeID may or may not be in tblMailsSent with some other MailID's but definitely not with the specific one I am looking for.

I find my own method for doing this rather clumsy, so do you happen to have a nice recipe?

View 3 Replies View Related

Queries :: Update Table Based On Condition?

Aug 7, 2015

I want to update a table called tblFinalOrder, that looks like this:

In particular, I want to update each column separately with the number 1 taken from table tblSAP_XWP_SW:

My problem is that Access doesn't properly update the table how I want. I join both tables using an INNER JOIN on the SAP number. In the column AEMenge you see some 1's. So what he should do is writing these 1's into the appropriate column in my tblFinalOrder table. The condition is that the SAP number must already be in my tblSAP_XWP_SW table. If he doesn't find a 1, then skip it.

Here is my code so far. This one should update column "DynaCT". The funny thing is that DynaCT isn't available in my columnlabel column but he writes a 1 anyways (or in this case anohter number, I was playing around with it). This is what I don't understand.

Code:
UPDATE tblFinalOrder AS a
INNER JOIN tblSAP_XWP_SW AS b
ON a.SAPNr = b.sapxwpsw_sapnr
SET a.DynaCT = 1
WHERE a.SAPNR IN (SELECT sapxwpsw_sapnr FROM tblSAP_XWP_SW);

I mean, he should only write the 1 into the specific column of table tblFinalOrder, if he finds the SAP number in tblSAP_XWP_SW and if there is a 1 in this line in column AEMenge.

View 3 Replies View Related

Queries :: Condition Format A Date Field

Aug 9, 2015

condition formatting a date field in access.The query used for this field produces a date or "NA" based on the formula below. so when the date shows up as "NA" then i have set the condition formatting of the cell to grey and this works works well. but when it shows up with a date it doesnt format to a grey.the formatting pane has these two expressions

1. Q_Induction_Date = "NA" then grey the cell

2. Q_Induction_Date < DATE() then grey the cell and this DOESNT work. i have also tried the function Now() and that doesnt work either.

Formula i use in the query is

Q_Induction_Date: IIf([y].[INDUCTION_NA]=-1,"NA",IIf(IsNull([induction_date]),"NA",Format([induction_date],"dd/mm/yyyy")))

View 4 Replies View Related

Forms :: Recordset Of Subform Inside Another Subform Which Is Inside A Mainform

Dec 16, 2013

I'm having a problem with the syntax of a recordset of a Datasheet inside a subform which is also inside a Main Form.

Main Form - frm_1_0_LMS
Subform - frm_1_4_0_TeamApprovals
Subform(Datasheet) - frm_1_4_1_TeamApprovalsList

Here is my code:

Code:

Dim rs As DAO.Recordset
Set rs = Forms!frm_1_0_LMS.frm_1_4_0_TeamApprovals.frm_1_4_1_TeamApprovalsList.Form.Recordset
If Not (rs.EOF And rs.BOF) Then
Forms!frm_1_4_2_ApproveDeclineUserLeave.Controls("lblFiledDateLeave").Caption = rs!Leave_Date
End If

I am getting this error: Object doesn't support this property or method

View 1 Replies View Related

Queries :: IIF Condition - Displaying All The Records Including Null

Aug 26, 2013

I want to list all the records which contains data as per my filter form field company.

I have tried this

Like IIf(IsNull([Forms]![Filter]![COMPANY]),"*","*" & [Forms]![Filter]![COMPANY] & "*")

problem is this i want to display all the records including null, but this code only show all records except null

Like IIf(IsNull([Forms]![Filter]![COMPANY]),"*" here we have to add codes for null values also but i don't know how ,"*" & [Forms]![Filter]![COMPANY] & "*")

View 10 Replies View Related

Queries :: Multiple Query Criteria IIF Statement - True Condition

Feb 24, 2015

I'm trying to have a single or multiple query criteria based on what the user checks on a form.

I can't get the True condition to work at all, I get no records. Here is what I'm using

IIf([Forms]![FrmAttendanceLogsRpt]![BlkFilter]=-1,[TempVars]![EID] Or 86,[TempVars]![EID])

If I just put
[TempVars]![EID] Or 86
in the Criteria it works just fine.

View 14 Replies View Related

Parameters In Queries

Jul 31, 2007

What is the meaning of the (rightclick)menu, parameter option?
If i want to create a parameter query like

SELECT * FROM Table1 WHERE Field1 = [ParameterField1]

Why should i use the rightclick menu? What's the added value of this menu item?

Thx!
Guus

View 1 Replies View Related

Parameters In Queries

Aug 19, 2015

I have a report that has two sub reports. The sub reports are based on two different queries that have a parameter in each. When I run the report it prompts me to enter the two parameters for each record (there could be 30 or more records), how do I get the parameters to only ask me once and pull all records? My parameter is >[Continued ED Starting After XX/XX/XXXX] and the other parameter is >[Credits Starting After Date: XX/XX/XXXX], so I would like to just enter this information once and return all records with that criteria and not have to enter the information 30 or more times to get all records.

View 9 Replies View Related

Help Coding Parameters For Queries

Nov 3, 2006

What I am trying to do is create 3 (or more) parameters for a query from a single table. Lets use this for example:

Table Name= "tblExample"
Field Name "A" with Perameter "1"
Field Name "B" with Perameter "2"
Field Name "C" with Perameter "3"
(All from Table= "tblExample")

My intentions are that when the query is run, the user is asked to include 3 subjects (1 subject per perameter; 3 perameters total that pop up). But I am having trouble making it so that if a random person using this query doesn't know or can't remember 1 or 2 of the subjects they are looking for, the query will just (in a sense) ignore the two blank parameters the user has left alone, and just clicked the "ok" button without entering anything, and use the 1 parameter that it was given a subject for, to filter/query out a result.

If you beleive you will have trouble explaining this to me, I'll use this as an example:

Table Name: "tblExample"
Field Name: "A" with Parameter "1"
Field Name: "B" with Parameter "2"
Field Name: "C" with Parameter "3"
(All from Table: "tblExample")

The user uses the query and is asked by the first parameter for input. The user isn't sure, and clicks ok without entering anything, and parameter 2 pops up. The user then enters a subject of which he/she knows to look for and clicks "ok". Then the final parameter asks the user for input, and the user again doesn't know, or can't remember so he/she just presses the "ok" button.
What would be the coding for this kind of parameter that if nothing is entered, the parameter is ignored?

In desperate need of assistance. Thanks in advnace

View 12 Replies View Related

Parameters/expressions In Queries

Mar 17, 2008

Hello again,

I have a query which has a parameter called [Enter Date as DD/MM/YYYY].
This filters out records from my table which match those entered by the user.
However, when the query is run, Access is asking the user to enter the criteria twice. The first time it is labelled Expr1, the second time it is Enter Date as DD/MM/YYYY. There is obviously something wrong in my query, can anybody point me in the right direction here?

Thanks in advance;)

swifty

View 4 Replies View Related

Queries :: Query Asking For Parameters?

Dec 1, 2013

I have a query that pulls information from two tables. Some of the fields that are being queried share the same name in the tables, [Reimbursed_Amount] and [Cancel_Fee] specifically. In Design View I have specified that I only want the query to pull these fields from the Event Information table. An error occurs when I try to run it, saying that I need to define which table the field is from in the SQL code.

But then after I added clarification in the SQL, when I run the query it now prompts for a parameter for each of these fields. Why is this happening? I leave it blank, so a parameter has no impact on the query. How can I stop this?

Here's the SQL, after I added the table clarification:

Code:
SELECT (Sum(nz([Program_Cost])+nz([Millage_Fee])+nz([Auditorium_Cost])+nz([Cancel_Fee].[Event Information])-nz([Reimbursed_Amount].[Event Information]))) AS Total_Cost, [Shared Billing Information].Paid, [Shared Billing Information].Shared_Billing_ID, [Event Information].Shared_Billing_ID
FROM [Shared Billing Information] RIGHT JOIN [Event Information] ON [Shared Billing Information].Shared_Billing_ID = [Event Information].Shared_Billing_ID

[Code] ....

View 7 Replies View Related

Passing Parameters From Form To Queries

Mar 23, 2006

Good Afternoon,

I am trying to create a form where a user will enter in a value into a text field. Afterwards, when the user clicks "Enter", a query will run and will LOOK FOR THE VALUE THAT WAS ENTERED INTO THE TEXT FIELD. i.e.
User enters their address into the field and clicks the enter button.
Afterwards, a query will run like
select * from customers where address = @address <== the value the user entered into the text field. This is where the mystery lies. How do you pass values?????

Thanks,
Nervous Jervous

View 6 Replies View Related

Crosstab Queries Parameters Problems

Feb 5, 2008

I am running Access 2003
I am get the following Error "Run Time Error 3001 Invalid Argument"

What I am trying to do is append data to a table based off a crosstab query and then open a form which its record source is the table I just append. The code as follows.

Dim qr As QueryDef
Dim dtDate As Date
Dim intPayment As Integer

'Delete old data from temp table
DoCmd.OpenQuery ("qryDeleteTempDrillDown1-Detail")

dtDate = Forms![frmBalance].txtDate
intPayment = FindPaymentCycle(Forms![frmBalance].txtDate)

'append data
Set qr = CurrentDb.QueryDefs("qryDrillDown1-Detail")
qr.Parameters("PaymentCycle") = intPayment
qr.Parameters("DateBalancing") = dtDate
qr.Execute ' THIS IS WHERE I AM GETTING MY ERROR:mad:

DoCmd.OpenForm ("frmDrillDown1-Detail")

The append query is made up of a crosstab query which is made up of a union query, which is made up of 14 separate select queries. 7 of the select queries have the same parameter and the parameter is defined in each of the query. 2 of the seven queries have a second parameter that is the same, which is also defined in their query. I also have the parameters defined in the crosstab query. And I have the parameters defined in my append query.

I don't know why I am getting the error other then my parameters are not being feed through. Any thoughts on this would be greatly appreciated.

View 2 Replies View Related







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