MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 14th, 2012, 09:16 PM
faizy999 faizy999 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 116 faizy999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 34 m 46 sec
Reputation Power: 10
Talking Today MTD and YTD Values

I have to write a query gathers all sold product from db for the given date as well as for that month and year its simple yes

Code:
-- For Given Date 
Select A.Quantity
From Products As A
Where A.Date = '01-01-2012'

-- Month of Given Date
Select A.Quantity
From Products As A
Where Month(A.Date) = Month('01-01-2012') And Year(A.Date) = Year('01-01-2012')

-- Year of Given Date
Select A.Quantity
From Products As A
Where  Year(A.Date) = Year('01-01-2012')


Now i m stuck with the year as its not a calender year but its a fiscal year which starts from 1 Oct 2011 and ends on 30 Sep 2012 now how can i implement this in year value query need assistance.

Reply With Quote
  #2  
Old November 15th, 2012, 02:35 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,349 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 20 m 59 sec
Reputation Power: 390
Code:
declare @year int
declare @date datetime,@startdate datetime,@enddate datetime

set @date = '2012-01-01'  --

set @year = year(@date) - case when @month < 10 then 1 else 0 end

set @startdate = datefromparts(@year,10,1)
set @enddate = datefromparts(@year+1,10,1)

select products.Quantity
  from Products
 Where Products.Date >= @startdate
   and Products.Date < @enddate

Reply With Quote
  #3  
Old November 15th, 2012, 11:02 PM
faizy999 faizy999 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 116 faizy999 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 34 m 46 sec
Reputation Power: 10
Thanks swampBoogie this resolves the issue.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Today MTD and YTD Values

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap