473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Multiple Rows Into One - Revisted

I was searching the threads about combing multiple rows into one and
found some good stuff, but need your help to expand on it.

I have a table as follows

Policy Number DateOfTrans TransType BenefitAmt
1234 12/1/2006 Received $12,000
1234 12/3/2006 Approved $5,000
1234 12/5/2006 Paid $5,000

I want to get this on one line to look like:

PolicyNumber DateReceived DateApproved DatePaid BenefitAmount

The benefit amount shoudl be the Approve's benefit amount. If approved
is null, then use the received amount.

Possible?

Thanks,
Brian

Dec 21 '06 #1
5 1505
Use the Nz function.

If that does not completely meet your needs (it should), consider the IIF
function, but if and only if you do not have a large number of records to
return.

--
Darryl Kerkeslager

"BerkshireGuy" <be*************************@yahoo.comwrote
The benefit amount shoudl be the Approve's benefit amount. If approved
is null, then use the received amount.

Dec 21 '06 #2
I tried this, but its only returning one date. Each status has a date,
so I'd like to return the status of each date.

SELECT PolicyNumber, RDLastTransaction,
MAX(IIF(StatusDisplay="Received",StatusDisplay,Nul l)) AS ['Received'],
MAX(IIF(StatusDisplay="Paid",StatusDisplay,Null)) AS ['Paid'],
MAX(IIF(StatusDisplay="Not Taken",StatusDisplay,Null)) AS ['Not Taken']
FROM tblMyInfo
GROUP BY PolicyNumber, RDLastTransaction;

Darryl Kerkeslager wrote:
Use the Nz function.

If that does not completely meet your needs (it should), consider the IIF
function, but if and only if you do not have a large number of records to
return.

--
Darryl Kerkeslager

"BerkshireGuy" <be*************************@yahoo.comwrote
The benefit amount shoudl be the Approve's benefit amount. If approved
is null, then use the received amount.
Dec 21 '06 #3
3 queries, one for each transtype, including the benefitAmt
a 4th query, combining the first 3 queries,
and with a field like nz(qryApproved.benefitAmt,
qryReceived.benefitAmt)
BerkshireGuy wrote:
I was searching the threads about combing multiple rows into one and
found some good stuff, but need your help to expand on it.

I have a table as follows

Policy Number DateOfTrans TransType BenefitAmt
1234 12/1/2006 Received $12,000
1234 12/3/2006 Approved $5,000
1234 12/5/2006 Paid $5,000

I want to get this on one line to look like:

PolicyNumber DateReceived DateApproved DatePaid BenefitAmount

The benefit amount shoudl be the Approve's benefit amount. If approved
is null, then use the received amount.

Possible?

Thanks,
Brian
Dec 21 '06 #4
Ben
I agree with the last entry, you need a query to turn each element into
a row and then another query to bring it all together (assuming your
table name is policy, and I've added an '_' to the id).

Something like this should work great:

SELECT policy.policy_number, [a].DateReceived, [b].DateApproved,
[c].DatePaid, IIf([b].[benefitamt]>0,[b].[benefitamt],[a].[benefitamt])
AS totalbenefitamt
FROM ((policy INNER JOIN
(SELECT policy.policy_number, Max(policy.dateoftrans) AS DateReceived,
policy.transtype, policy.benefitamt
FROM policy
GROUP BY policy.policy_number, policy.transtype, policy.benefitamt
HAVING (((policy.transtype)="received"))) a ON policy.policy_number =
[a].policy_number) INNER JOIN
(SELECT policy.policy_number, Max(policy.dateoftrans) AS DateApproved,
policy.transtype, policy.benefitamt
FROM policy
GROUP BY policy.policy_number, policy.transtype, policy.benefitamt
HAVING (((policy.transtype)="approved"))) b ON policy.policy_number =
[b].policy_number) INNER JOIN
(SELECT policy.policy_number, Max(policy.dateoftrans) AS DatePaid,
policy.transtype, policy.benefitamt
FROM policy
GROUP BY policy.policy_number, policy.transtype, policy.benefitamt
HAVING (((policy.transtype)="paid")))
c ON policy.policy_number = [c].policy_number
GROUP BY policy.policy_number, [a].DateReceived, [b].DateApproved,
[c].DatePaid,
IIf([b].[benefitamt]>0,[b].[benefitamt],[a].[benefitamt]);


BerkshireGuy wrote:
I was searching the threads about combing multiple rows into one and
found some good stuff, but need your help to expand on it.

I have a table as follows

Policy Number DateOfTrans TransType BenefitAmt
1234 12/1/2006 Received $12,000
1234 12/3/2006 Approved $5,000
1234 12/5/2006 Paid $5,000

I want to get this on one line to look like:

PolicyNumber DateReceived DateApproved DatePaid BenefitAmount

The benefit amount shoudl be the Approve's benefit amount. If approved
is null, then use the received amount.

Possible?

Thanks,
Brian
Dec 21 '06 #5
Oh....

How would this be against a table with 300,000 records?
Ben wrote:
I agree with the last entry, you need a query to turn each element into
a row and then another query to bring it all together (assuming your
table name is policy, and I've added an '_' to the id).

Something like this should work great:

SELECT policy.policy_number, [a].DateReceived, [b].DateApproved,
[c].DatePaid, IIf([b].[benefitamt]>0,[b].[benefitamt],[a].[benefitamt])
AS totalbenefitamt
FROM ((policy INNER JOIN
(SELECT policy.policy_number, Max(policy.dateoftrans) AS DateReceived,
policy.transtype, policy.benefitamt
FROM policy
GROUP BY policy.policy_number, policy.transtype, policy.benefitamt
HAVING (((policy.transtype)="received"))) a ON policy.policy_number =
[a].policy_number) INNER JOIN
(SELECT policy.policy_number, Max(policy.dateoftrans) AS DateApproved,
policy.transtype, policy.benefitamt
FROM policy
GROUP BY policy.policy_number, policy.transtype, policy.benefitamt
HAVING (((policy.transtype)="approved"))) b ON policy.policy_number =
[b].policy_number) INNER JOIN
(SELECT policy.policy_number, Max(policy.dateoftrans) AS DatePaid,
policy.transtype, policy.benefitamt
FROM policy
GROUP BY policy.policy_number, policy.transtype, policy.benefitamt
HAVING (((policy.transtype)="paid")))
c ON policy.policy_number = [c].policy_number
GROUP BY policy.policy_number, [a].DateReceived, [b].DateApproved,
[c].DatePaid,
IIf([b].[benefitamt]>0,[b].[benefitamt],[a].[benefitamt]);


BerkshireGuy wrote:
I was searching the threads about combing multiple rows into one and
found some good stuff, but need your help to expand on it.

I have a table as follows

Policy Number DateOfTrans TransType BenefitAmt
1234 12/1/2006 Received $12,000
1234 12/3/2006 Approved $5,000
1234 12/5/2006 Paid $5,000

I want to get this on one line to look like:

PolicyNumber DateReceived DateApproved DatePaid BenefitAmount

The benefit amount shoudl be the Approve's benefit amount. If approved
is null, then use the received amount.

Possible?

Thanks,
Brian
Dec 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
20
by: p175 | last post by:
Hi people, I have a stored procedure that creates many Global temporary session tables. Into each of these tables go the results of various processing using relational division all keyed and...
9
by: TC | last post by:
I need to design a system which represents multiple "projects" in SQL Server. Each project has the same data model, but is independent of all others. My inclination is to use one database to store...
3
by: =?Utf-8?B?S2F5xLFoYW4=?= | last post by:
In my project,i added datagridview to my form , i transfered my table to datagridview and added multiple rows and when i called dataadapther.update ,,result is ok. But when i tried it for the...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
58
by: bonneylake | last post by:
Hey Everyone, Well recently i been inserting multiple fields for a section in my form called "serial". Well now i am trying to insert multiple fields for the not only the serial section but also...
482
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if this is more of a coldfusion problem or a javscript problem. So if i asked my question in the wrong section let me know an all move it to the correct place. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.