Using a Group By statement when filling a data table
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Using a Group By statement when filling a...Expand / Collapse
Author
Message
Posted 03/14/2008 12:28:48 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 06/12/2008 10:28:41 AM
Posts: 303, Visits: 434
I'm using a sql statement like the following:

SELECT CheckDtl.AcctNo, Transactions.ClientKey as ClientKey,  
SUM(CASE WHEN CheckDtl.Amt > 0 THEN CheckDtl.Amt END) AS CreditAmt,
SUM(CASE WHEN CheckDtl.Amt < 0 THEN ABS(CheckDtl.Amt) END) AS DebitAmt
FROM CheckDtl 
INNER JOIN CheckHdr ON CheckHdr.CheckHdrKey=CheckDtl.CheckHdrKey 
INNER JOIN Transactions ON Transactions.TransKey=CheckHdr.TransKey 
WHERE CheckHdr.CheckType<>5  AND CheckHdr.CheckDate >= '01-Jul-2006'
  AND CheckHdr.CheckDate <= '31-Jul-2006'
GROUP BY CheckDtl.AcctNo, Transactions.ClientKey
ORDER BY CheckDtl.AcctNo, Transactions.ClientKey

Now this query returns exactly what I want when run against the database, but when I try to use it in a FillDataTable method I get the following error:

System.ArgumentException - Column 'CheckHdrKey' does not belong to table CheckDtl.

Now, is it still looking for the primary and foreign keys to be in the query even when I'm not using them?  I can't figure out a way to put them in the query and produce what I want with the grouping the way I have it.  Please give me some input here, or let me know if I'm doing something wrong.  Thanks.

Post #14891
Posted 03/14/2008 1:06:38 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 11:13:06 AM
Posts: 4,104, Visits: 4,176
Well, let me tell you this first, double check your query.  If the query works within SQL Server Management Studio query then it will not be affected through the FillDataTable.  I will tell you a little story here...the other day I was getting one value when executing a query within SQL Server Management Studio and another when I called ExecuteScalar on the BO....I would have SWORN there was an issue...I kept looking over my command, debugged the ES Server, even got another pair of eyes to look at my query.  Over an hour later...um...Ben finally saw what was wrong...I left of an @ in front of one of my parameters.

So it happens to us all...since I do not have your data structures it is hard for me to tell you what is exactly wrong with your query.  But I would double-check what you are doing there.

I am sure that the query that you posted was just to show me some values, but you should definitely be using parameters in your actual query command versus embedded values.

Post #14893
Posted 03/14/2008 2:22:22 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 06/12/2008 10:28:41 AM
Posts: 303, Visits: 434
Ok, you were right...sort of.  Haha.

My SQL was fine, the query worked correctly.  But, I had something in the Navigated event that was using a property that wasn't returned by that query in that specific case.  It confused me because the error wasn't breaking into the event...it was breaking into the FillDataTable method.  Either way, it's fixed now, so thanks for the point in the right direction.

Post #14910
Posted 03/14/2008 2:28:51 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 11:13:06 AM
Posts: 4,104, Visits: 4,176
No problem...I figured it was something along those lines.  Glad you found it
Post #14914
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 5:53pm

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.047. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.