In query, how can I pull data for one or the other or both..

  • Thread starter Thread starter add1023
  • Start date Start date
A

add1023

I have a spreadsheet using 2 criteria. THe first is date range, tha
is fine and under control. The second is a column that has a T or a
N. I am using a parameter query and you enter a t or an N when statin
parameters. Anyway, typically I only need Ts but sometimes I nee
both. How can I set up the query so that it runs T, N, or Both
 
add1023 said:
I have a spreadsheet using 2 criteria. THe first is date range, that
is fine and under control. The second is a column that has a T or an
N. I am using a parameter query and you enter a t or an N when stating
parameters. Anyway, typically I only need Ts but sometimes I need
both. How can I set up the query so that it runs T, N, or Both?

I presume this is an Access table datasheet, not an Excel spreadsheet?

Try using a query with a criterion of

[Enter T, N, or blank for both:] OR [Enter T, N, or blank for both:] IS NULL

If the user leaves it blank all records that match the date criterion will
be returned; if they enter T or N only those records will.

John W. Vinson [MVP]
 
add1023 said:
The second is a column that has a T or an
N. I am using a parameter query and you enter a t or an N when stating
parameters. Anyway, typically I only need Ts but sometimes I need
both. How can I set up the query so that it runs T, N, or Both?

I'd suggest using a character to use when the user wants to select
using both 'T' and 'N', for example 'B', and make it the default value
so it may be omitted (better than testing for a NULL parameter value,
IMO).

For example:

CREATE TABLE Test (
key_col INTEGER NOT NULL PRIMARY KEY,
char_col CHAR(1) DEFAULT 'T' NOT NULL,
CHECK (char_col IN ('T', 'N'))
)
;
INSERT INTO Test VALUES (1, 'T')
;
INSERT INTO Test VALUES (2, 'N')
;
CREATE PROCEDURE TestProc (
arg_char CHAR(1) = 'B'
) AS
SELECT key_col, char_col
FROM Test
WHERE char_col =
IIF(arg_char = 'B', 'T', arg_char)
OR char_col =
IIF(arg_char = 'B', 'N', arg_char)
;

Executing the procedure using:

EXEC TestProc 'T'

selects row 1

Using:

EXEC TestProc 'N'

selects row 2.

Using:

EXEC TestProc 'B'

or

EXEC TestProc

selects rows 1 and 2.

Using any other value:

EXEC TestProc 'X'

selects no rows.

Jamie.

--
 
add1023 said:
I have a spreadsheet using 2 criteria. THe first is date range, that
is fine and under control. The second is a column that has a T or an
N. I am using a parameter query and you enter a t or an N when stating
parameters. Anyway, typically I only need Ts but sometimes I need
both. How can I set up the query so that it runs T, N, or Both?


I suggest just reinstalling windows+adding Windows xp proffesional
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top