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
 General SQL Server Forums
 New to SQL Server Programming
 help adding columns

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2008-01-25 : 17:31:05
I have this code and it should bring back code for the month i put in in the set statement. When i put in say may i need to add up numbers for all months prior in the total projections call em and im lost

Declare @Division as Varchar(15)
Declare @Date as Varchar(7)

Set @Division = 'Del Sol'
Set @Date = '05/2008'

Select [Month], Sum(Projection) as ProjectionTotal
From Reporting.dbo.RetailSalesComparison_ProjectionsView PV
Inner Join DelsolNet2.dbo.StoreGroup SG on PV.StoreID = OrderStoreID
Where @Division = Case DivisionID When 10 then 'Del Sol'
When 11 then 'Cariloha'
When 12 then 'Sol Kids' else 'Notta' End
and Month([Month]) = Left(@Date,2) and Year([Month]) = Right(@Date,4)

Group By [Month]

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-25 : 23:00:29
Didnt understand you fully. Guess you want all data until month selected then for the year. Then use this.

and Month([Month]) <= Left(@Date,2) and Year([Month]) = Right(@Date,4)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-28 : 01:11:32
Also use proper DATETIME parameter and dont handle dates as varchars

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -