a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

SQL Current Month & Year

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> ASP and Database >> SQL Current Month & Year
Page: [1]
 
Bnugent

 

Posts: 257
From: Tampa Florida Tampa, FL USA
Status: offline

 
SQL Current Month & Year - 1/31/2007 15:40:12   
I have tried searching for this answer, thinking it would appear in a lot of posts, and I couldnt find an answer that worked for me...so here goes...

I am currently using this SQL Statement to pull the daily invoices:
SELECT SOP30200.SOPTYPE, SOP30200.SOPNUMBE, SOP30200.DOCDATE, SOP30200.CSTPONBR, SOP30200.CUSTNMBR, SOP30200.CUSTNAME, SOP30200.ShipToName, SOP30200.ADDRESS1, SOP30200.CITY, SOP30200.STATE, SOP30200.ZIPCODE, SOP30200.PHNUMBR1, SOP30200.SUBTOTAL FROM SOP30200 WHERE SOP30200.SOPTYPE = '3' AND convert(varchar(10),SOP30200.DOCDATE,101) = convert(varchar(10),getdate(),101) ORDER BY SOP30200.SUBTOTAL DESC, SOP30200.CUSTNMBR ASC;

I would like to be able to pull 2 more ranges...One being the current Month...The other being the Current year...Can anyone help me here?

Thanks in advance!

_____________________________

Brian---
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SQL Current Month & Year - 1/31/2007 15:48:09   
Month calculation looks like this:

...DATEPART(m, theDateField) AS ItemMonth,...

Year calculations look like this:

...DATEPART(yyyy, theDateField) AS ItemYear,...

Those will return integer values, month being 1 to 12 and year being a 4 digit number. That help?

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to Bnugent)
Bnugent

 

Posts: 257
From: Tampa Florida Tampa, FL USA
Status: offline

 
RE: SQL Current Month & Year - 1/31/2007 15:50:29   
I had tried that...But cant figure out where to change without getting an error...So this line..

quote:

WHERE SOP30200.SOPTYPE = '3' AND convert(varchar(10),SOP30200.DOCDATE,101) = convert(varchar(10),getdate(),101)


What would I change to get it to pull current month instead of current day like it does now?

_____________________________

Brian---

(in reply to rdouglass)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: SQL Current Month & Year - 1/31/2007 15:53:36   
quote:

WHERE DATEPART(m, theDateField) = " & DatePart('m',Date()) & ",...


That any help?

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to Bnugent)
Bnugent

 

Posts: 257
From: Tampa Florida Tampa, FL USA
Status: offline

 
RE: SQL Current Month & Year - 1/31/2007 16:33:32   
I think I am on the right track now. Thanks...But here is whats happending...Here is my new code:

AND DATEPART(m, SOP30200.DOCDATE) = DATEPART(m,GetDate())

Its returning all the sales from January...But its including sales from 2005, 2006 and 2007...I wish to only have sales from the current month of the current year shown...I tried adding:

AND DATEPART(y, SOP30200.DOCDATE) = DATEPART(y,GetDate())

But that didnt work either...

_____________________________

Brian---

(in reply to rdouglass)
BeTheBall

 

Posts: 6385
Joined: 6/21/2002
From: West Point Utah USA
Status: offline

 
RE: SQL Current Month & Year - 1/31/2007 17:00:43   
You are on the right track by including a clause to deal also with the year. However, the year requires 4 'y's:

AND DATEPART(yyyy, SOP30200.DOCDATE) = DATEPART(yyyy,GetDate())

_____________________________

Duane

Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.

(in reply to Bnugent)
Bnugent

 

Posts: 257
From: Tampa Florida Tampa, FL USA
Status: offline

 
RE: SQL Current Month & Year - 1/31/2007 17:04:53   
worked like a charm:

For those of you who may need it:

AND DATEPART(m, SOP30200.DOCDATE) = DATEPART(m, GetDate()) AND DATEPART(yyyy, SOP30200.DOCDATE) = DATEPART(yyyy, GetDate())

Thanks to all who helped!!!!!!

_____________________________

Brian---

(in reply to BeTheBall)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> ASP and Database >> SQL Current Month & Year
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts