SQL where, case between or equal date vs datetime -


i'm trying figure out if there many moving pieces in query or not. need check if date on friday, corresponding value following monday. other day, next day. can 'next day' part work no problems, friday monday piece fails. making little tougher a.change_date in date format , b.load_date in datetime format.

select *   a, b   a.account_number = b.account_number   , a.change_date    case  when datepart(dw, a.change_date) = 5             between (cast(dateadd(dd, -4, b.load_date) date)) , (cast(dateadd(dd, -3, b.load_date) date))         else             = cast(b.load_date) date) , cast(dateadd(dd, -1, b.load_date) date)     end   , a.account_number in  (xxxxx.....) 

any thoughts on how make happen appreciated. should return rows account_numbers exist in last , statement. i've looked @ long today , not made enough progress.

i don't know full schema, here quick example local variables.

declare @somedate datetime = '2016-04-15 15:17:00.497'--getdate() declare @nextdate datetime  select @nextdate = case when datepart(dw,@somedate)=6 @somedate+3 else @somedate+1 end   select @nextdate nextdate 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -