Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 help in query

Author  Topic 

kamii47
Constraint Violating Yak Guru

353 Posts

Posted - 2013-03-02 : 10:11:21
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

52326 Posts

Posted - 2013-03-02 : 12:07:44
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)

17689 Posts

Posted - 2013-03-04 : 03:12:34
[code]select TOP 6
week_number
,year
from accounting_calender
where (year * 100) + week_number <= (2013 * 100) + 3
order by year desc, week_number[/code]



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-04 : 04:24:33
hmm...i thought op wanted last x weeks from recent week

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

Go to Top of Page
   

- Advertisement -