paramaterized Union query?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH] AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS Charge, MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
 
Jonefer- one thing you can do is just fill the same datatable with each
query, in sql server you can batch them as well (although Access doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select in
the Union queries) or have separate adapters, calling fill on each adapter
but using the *same* datatable each time.

I believe this will get you what you want.
 
by the way, I wrote you an e-mail as requested for my other question
Did you see it yet?

===
Continuing on with the Parameterized Union query:
One of the complexities that I haven't even touched - is that I need to JOIN
this UNION with a descriptor table that can only be attached AFTER the union
has been realized.

So, ok lets say I do a fill for each of the queries...
how do I then JOIN that result with the descriptor table ?

AFTER which, I will need to parameterize this before it becomes displayed in
the Datagrid.





W.G. Ryan eMVP said:
Jonefer- one thing you can do is just fill the same datatable with each
query, in sql server you can batch them as well (although Access doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select in
the Union queries) or have separate adapters, calling fill on each adapter
but using the *same* datatable each time.

I believe this will get you what you want.
jonefer said:
This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using
ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH] AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS Charge,
MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
 
Sorry for not getting back to you on the first issue- I'll reply shortly.

Regarding the second one, once you have the UNIONed table, you need to join
it to another table, is that correct? You can fill a datatable for
descriptor and then use a DataRelation back to the unioned table (if it's an
inner join).
jonefer said:
by the way, I wrote you an e-mail as requested for my other question
Did you see it yet?

===
Continuing on with the Parameterized Union query:
One of the complexities that I haven't even touched - is that I need to
JOIN
this UNION with a descriptor table that can only be attached AFTER the
union
has been realized.

So, ok lets say I do a fill for each of the queries...
how do I then JOIN that result with the descriptor table ?

AFTER which, I will need to parameterize this before it becomes displayed
in
the Datagrid.





W.G. Ryan eMVP said:
Jonefer- one thing you can do is just fill the same datatable with each
query, in sql server you can batch them as well (although Access doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select in
the Union queries) or have separate adapters, calling fill on each
adapter
but using the *same* datatable each time.

I believe this will get you what you want.
jonefer said:
This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using
ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH] AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS Charge,
MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
 
Ok, I was successfull in filling my datagrid with the basic Union,
which includes the fields, Type, Benefit, and Change
Datagrid is called DGBenefit and my dataset is called dsBenefit1

Could you walk me through adding the related description field From a table
called: BNFT to my current Datagrid DGBenefit

The related fields are 'Benefit' and 'Change' and the Column I want to add
is "Description"



W.G. Ryan - MVP said:
Sorry for not getting back to you on the first issue- I'll reply shortly.

Regarding the second one, once you have the UNIONed table, you need to join
it to another table, is that correct? You can fill a datatable for
descriptor and then use a DataRelation back to the unioned table (if it's an
inner join).
jonefer said:
by the way, I wrote you an e-mail as requested for my other question
Did you see it yet?

===
Continuing on with the Parameterized Union query:
One of the complexities that I haven't even touched - is that I need to
JOIN
this UNION with a descriptor table that can only be attached AFTER the
union
has been realized.

So, ok lets say I do a fill for each of the queries...
how do I then JOIN that result with the descriptor table ?

AFTER which, I will need to parameterize this before it becomes displayed
in
the Datagrid.





W.G. Ryan eMVP said:
Jonefer- one thing you can do is just fill the same datatable with each
query, in sql server you can batch them as well (although Access doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select in
the Union queries) or have separate adapters, calling fill on each
adapter
but using the *same* datatable each time.

I believe this will get you what you want.
This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using
ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH] AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS Charge,
MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
 
This should help, let me konw if it doesn't .
http://www.knowdotnet.com/articles/datarelation.html

BTW, I haven't forgotten about the other issue - just kinda busy but I'll
reply in full tonight ;-)
jonefer said:
Ok, I was successfull in filling my datagrid with the basic Union,
which includes the fields, Type, Benefit, and Change
Datagrid is called DGBenefit and my dataset is called dsBenefit1

Could you walk me through adding the related description field From a
table
called: BNFT to my current Datagrid DGBenefit

The related fields are 'Benefit' and 'Change' and the Column I want to add
is "Description"



W.G. Ryan - MVP said:
Sorry for not getting back to you on the first issue- I'll reply shortly.

Regarding the second one, once you have the UNIONed table, you need to
join
it to another table, is that correct? You can fill a datatable for
descriptor and then use a DataRelation back to the unioned table (if it's
an
inner join).
jonefer said:
by the way, I wrote you an e-mail as requested for my other question
Did you see it yet?

===
Continuing on with the Parameterized Union query:
One of the complexities that I haven't even touched - is that I need to
JOIN
this UNION with a descriptor table that can only be attached AFTER the
union
has been realized.

So, ok lets say I do a fill for each of the queries...
how do I then JOIN that result with the descriptor table ?

AFTER which, I will need to parameterize this before it becomes
displayed
in
the Datagrid.





:

Jonefer- one thing you can do is just fill the same datatable with
each
query, in sql server you can batch them as well (although Access
doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select
in
the Union queries) or have separate adapters, calling fill on each
adapter
but using the *same* datatable each time.

I believe this will get you what you want.
This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using
ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH]
AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS
Charge,
MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
 
I should be able to use that thorough explanation for reference
when my application becomes more complex, thank you.

Let me just clarify something, since the field that I'm adding is a
one-to-one relation (which I feel was a bad design on the DBA's part)

both tables in my dataset (dsBenefit) now:
BNFT (which has the desc field)
Membership (which is missing the Desc field)

Can I just add the 'desc' column to Table(0)?
After I make the 2 data relations
Benefit - BNF
Change -CHG

giving me the final dataset of
Type, Benefit, Change, Desc

(the first 3 from 'membership' table, and Desc from BNFT table)

Because all I need is one table.



W.G. Ryan - MVP said:
This should help, let me konw if it doesn't .
http://www.knowdotnet.com/articles/datarelation.html

BTW, I haven't forgotten about the other issue - just kinda busy but I'll
reply in full tonight ;-)
jonefer said:
Ok, I was successfull in filling my datagrid with the basic Union,
which includes the fields, Type, Benefit, and Change
Datagrid is called DGBenefit and my dataset is called dsBenefit1

Could you walk me through adding the related description field From a
table
called: BNFT to my current Datagrid DGBenefit

The related fields are 'Benefit' and 'Change' and the Column I want to add
is "Description"



W.G. Ryan - MVP said:
Sorry for not getting back to you on the first issue- I'll reply shortly.

Regarding the second one, once you have the UNIONed table, you need to
join
it to another table, is that correct? You can fill a datatable for
descriptor and then use a DataRelation back to the unioned table (if it's
an
inner join).
by the way, I wrote you an e-mail as requested for my other question
Did you see it yet?

===
Continuing on with the Parameterized Union query:
One of the complexities that I haven't even touched - is that I need to
JOIN
this UNION with a descriptor table that can only be attached AFTER the
union
has been realized.

So, ok lets say I do a fill for each of the queries...
how do I then JOIN that result with the descriptor table ?

AFTER which, I will need to parameterize this before it becomes
displayed
in
the Datagrid.





:

Jonefer- one thing you can do is just fill the same datatable with
each
query, in sql server you can batch them as well (although Access
doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select
in
the Union queries) or have separate adapters, calling fill on each
adapter
but using the *same* datatable each time.

I believe this will get you what you want.
This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using
ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH]
AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS
Charge,
MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
 
I guess a better question from the beginning would have been:
how do I combine a bunch of fields from various tables into one dataset?

(most of the examples show a parent-child relationship - which my question
is not)


W.G. Ryan - MVP said:
This should help, let me konw if it doesn't .
http://www.knowdotnet.com/articles/datarelation.html

BTW, I haven't forgotten about the other issue - just kinda busy but I'll
reply in full tonight ;-)
jonefer said:
Ok, I was successfull in filling my datagrid with the basic Union,
which includes the fields, Type, Benefit, and Change
Datagrid is called DGBenefit and my dataset is called dsBenefit1

Could you walk me through adding the related description field From a
table
called: BNFT to my current Datagrid DGBenefit

The related fields are 'Benefit' and 'Change' and the Column I want to add
is "Description"



W.G. Ryan - MVP said:
Sorry for not getting back to you on the first issue- I'll reply shortly.

Regarding the second one, once you have the UNIONed table, you need to
join
it to another table, is that correct? You can fill a datatable for
descriptor and then use a DataRelation back to the unioned table (if it's
an
inner join).
by the way, I wrote you an e-mail as requested for my other question
Did you see it yet?

===
Continuing on with the Parameterized Union query:
One of the complexities that I haven't even touched - is that I need to
JOIN
this UNION with a descriptor table that can only be attached AFTER the
union
has been realized.

So, ok lets say I do a fill for each of the queries...
how do I then JOIN that result with the descriptor table ?

AFTER which, I will need to parameterize this before it becomes
displayed
in
the Datagrid.





:

Jonefer- one thing you can do is just fill the same datatable with
each
query, in sql server you can batch them as well (although Access
doesn't
support batching I believe).

So you just use an adapter with a batched command (one for each Select
in
the Union queries) or have separate adapters, calling fill on each
adapter
but using the *same* datatable each time.

I believe this will get you what you want.
This is a union query from an Access Database
But I will also be using SQL server

For the meantime in Access,

I want parameters MRN, [GROUP] and SGR

For the following UNION query - (how should I go about this using
ADO.NET?)

SELECT 'Inpatient' AS Type, [IN-BNFT] AS Benefit, [IN-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Outpatient' AS Type, [OUT-BNFT] AS Benefit, [OUT-BFCH]
AS
Charge, MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ancillary' AS Type, [ANC-BNFT] AS Benefit, [ANC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Emergency' AS Type, [EMR-BNFT] AS Benefit, [EMR-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Drug' AS Type, [DRG-BNFT] AS Benefit, [DRG-BFCH] AS
Charge,
MRN,
[GROUP], SGR
FROM Membership
UNION
SELECT 'Optical' AS Type, [OPT-BNFT] AS Benefit, [OPT-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Psych' AS Type, [PSY-BNFT] AS Benefit, [PSY-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Injection' AS Type, [INJ-BNFT] AS Benefit, [INJ-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'AIDSApp' AS Type, [CAA-BNFT] AS Benefit, [CAA-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Ext Care' AS Type, [ECF-BNFT] AS Benefit, [ECF-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
UNION
SELECT 'Claims ER' AS Type, [ERC-BNFT] AS Benefit, [ERC-BFCH] AS
Charge,
MRN, [GROUP], SGR
FROM Membership
 
Back
Top