Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 11-07-2006, 02:50 PM   #1 (permalink)
Forum Newbie
 
Join Date: Nov 2006
Posts: 1
Default C#-sql

I am trying to get a report and I know how to do it but I dont like the way of doing it. I have two tables: Customers(id,name etc..), Transactions (transId,customerId,transTotal, transDate etc..) in mssql

what I need is transaction total per month for each customer.

what I am trying to do is write a sql statement for each month and I have two parameters for sql select. startDate, endDate. It is easy to determine startDate (01/month/year), however i couldnt find an easy way of finding last day of the month. and I dont want to do it manually for each month. I need to loop it and there is also fucking february!!

is there any other way of doing this? need a little help, thx !

Last edited by talikardi; 11-07-2006 at 03:10 PM.
talikardi is offline   Reply With Quote
Old 11-08-2006, 06:10 AM   #2 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

if you are using Date object, you might get endDate by subtracting one day from next month.

however, what you are trying to achieve is too much simpler with something like this:

Quote:
select customerId, datepart(month,transDate), sum(transTotal) from Customers (nolock) c, Transactions (nolock) t where c.id=t.customerId and transDate >= ('01/01/'+convert(varchar,datepart(year,getdate()))) group by customerID, datepart(month,transDate)
the last AND statement might be unnecessary for your use and data..
__________________
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
noobie is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5