sql server - DateAdd( on parameter -


hello i'm writing report based on weekly sales, i've attained current figure correctly , works @firstdayofweek , @lastdayofweek parameters , im trying replicate previous week, know previous week -7 days behind

when run in clause

  , firstdayofweek = dateadd(day,-7,'2014/06/02')   , lastdayofweek = dateadd(day,-7,'2014/06/08') 

it works , figure pre quantity , correct enter image description here

but when parameter

and dateadd(day,-7,w.firstdayofweek) in (               select item               datawarehouse.dbo.ufnsplit(@firstdayofweek, ',')               )         , dateadd(day,-7,w.lastdayofweek) in (               select item               datawarehouse.dbo.ufnsplit(@lastdayofweek, ',')               ) 

i column headers nothing anywhere. ideas?

here code using execute stored proc:

exec weeklysalesandusw @bd=n'798664', @cgno=n'47', @scgno=n'01,02,03,04,05,06,07,08', @productclass=n'1', @‌​productcode=n'1108', @region=n'772', @firstdayofweek = '2014/06/02', @lastdayofweek = '2014/06/08'  

why isnt parameter passing through? why work if hard code date in when make dynamic gets nothing?

it's not working because reversed equation.

in code works, doing this:

and firstdayofweek = dateadd(day,-7,'2014/06/02') , lastdayofweek = dateadd(day,-7,'2014/06/08') 

notice subtracting 7 days hard-coded "parameters", , not columns in table.

now trying use dynamic parameter values, doing opposite:

and dateadd(day,-7,w.firstdayofweek) in (               select item               datawarehouse.dbo.ufnsplit(@firstdayofweek, ',')               )         , dateadd(day,-7,w.lastdayofweek) in (               select item               datawarehouse.dbo.ufnsplit(@lastdayofweek, ',')               ) 

you subtracting 7 days table column, , not parameter values.

you can correct removing minus (-) sign before both of 7's. because adding 7 left side of equation mathematically same subtracting 7 right side.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -