SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 help in query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kamii47
Constraint Violating Yak Guru

351 Posts

Posted - 03/02/2013 :  10:11:21  Show Profile  Reply with Quote
I am facing issues with my query

select week_number
,year
from accounting_calender
where week_number<=3
and week_number>3-6
and year=2013

here in this query im passing the week_number "3" and year "2013" through my reporting tool.

im getting the following output

| Week_number | year |
------------------------------
| 3 | 2013 |
| 2 | 2013 |
| 1 | 2013 |

but here in my accounting calender table i got even the entries for 2012 too.
so here im subtracting "-6", so it has to go to previous year weeks also..

iam looking for something like below output

| Week_number | year |
------------------------------
| 51 | 2012 |
| 52 | 2012 |
| 53 | 2012 |
| 3 | 2013 |
| 2 | 2013 |
| 1 | 2013 |

kindly guide me.

i have only read-only access

Kamran Shahid
Principle Engineer Development
(MCSD.Net,MCPD.net)

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/02/2013 :  12:07:44  Show Profile  Reply with Quote
do you've any other columns in accounting_calendar

like date,dateid etc?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17437 Posts

Posted - 03/04/2013 :  03:12:34  Show Profile  Reply with Quote
select TOP 6
       week_number
       ,year
from   accounting_calender
where  (year * 100) + week_number <= (2013 * 100) + 3
order by year desc, week_number




KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 03/04/2013 :  04:24:33  Show Profile  Reply with Quote
hmm...i thought op wanted last x weeks from recent week

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000