sql server - sql query to find stores open current week and last year -
i trying write query in sql server stores open last year , current week in 1 single query. condition should stores should open full week , not have single day missing in week. below query doesn't display openlastyear = '1' though store open last year, happens because store hasn't transacted in current week. want rectify through query.
my tables are:
my query below:
select ss.datekey, iif ((select sum(tablea.net) net tablea inner join tableb on tablea.datekey = tableb.datekey (tableb.weekcommencing = dbo.dimdate.weekcommencing) , (tablea.storeid = ss.storeid)) > 0, iif ((select count(tablea.storeid) wasopen tablea inner join tableb on tablea.datekey = tableb.datekey (tableb.weekcommencing = dbo.dimdate.weekcommencing) , (tablea.net not null) , (tablea.net > 0) , (tablea.storeid = tablea.storeid)) = 7, 1, 0), 0) openthisweek, iif ((select count(tablea.storekey) wasopen tablea inner join tableb on tablea.datekey = tableb.[datekeysametime] (tableb.financialwc = dbo.dimdate.financialwc) , (tablea.net not null) , (tablea.net > 0) , (tablea.storeid = ss.storeid)) = 7, 1, 0) openlastyear, ss.storeid tablea ss inner join dbo.dimdate on ss.datekey = dbo.dimdate.datekey
Comments
Post a Comment