java - How to check all values for a particular column in a week -


i have table called timesheet.in has below rows

  id status projid actid  date     1  pending  1     1     2014-aug-07     2  denied   1     2     2014-aug-08     3  saved    1     3     2014-aug-09     4  approved 1     4     2014-aug-10 

i have used below query getting desired result.

select * tbltimesheet  datepart(wk,spentdate) = 32 , ((timesheetstatus = 'pending' or timesheetstatus = 'approved') , (timesheetstatus <> 'saved' or timesheetstatus <> 'denied')) 

my expected result above query 0.but result 1.

 5  pending  1     1     2014-aug-11     6  pending  1     2     2014-aug-12     7  approved 1     3     2014-aug-13     8  approved 1     4     2014-aug-14 

this case query works.

select * tbltimesheet  datepart(wk,spentdate) = 32 , ((timesheetstatus = 'pending' or timesheetstatus = 'approved') , (timesheetstatus <> 'saved' or timesheetstatus <> 'denied')) 

my expected result above query 1.i result 1.

how write query above requirement in mssql. scenario 1 worked.but scenario2 not worked. how acheive desired result. appreciated!!!

note solution mysql, because tagged. uses mysql's standard defintion 'week' - appears differ fron own definition. may able use week(date,3) or similar if better matches definition.

 drop table if exists my_table;  create table my_table (id int not null auto_increment primary key ,status varchar(20) not null ,projid int not null ,actid int not null ,date date not null );  insert my_table values (1  ,'pending',1     ,1     ,'2014-08-07'), (2  ,'denied',   1     ,2     ,'2014-08-08'), (3  ,'saved',    1     ,3     ,'2014-08-09'), (4  ,'approved', 1     ,4     ,'2014-08-10');  select *,week(date) my_table; +----+----------+--------+-------+------------+------------+ | id | status   | projid | actid | date       | week(date) | +----+----------+--------+-------+------------+------------+ |  1 | pending  |      1 |     1 | 2014-08-07 |         31 | |  2 | denied   |      1 |     2 | 2014-08-08 |         31 | |  3 | saved    |      1 |     3 | 2014-08-09 |         31 | |  4 | approved |      1 |     4 | 2014-08-10 |         32 | +----+----------+--------+-------+------------+------------+  select x.*    my_table x    left    join my_table y      on week(y.date) = week(x.date)     , y.status not in ('approved','pending')   y.id null; +----+----------+--------+-------+------------+ | id | status   | projid | actid | date       | +----+----------+--------+-------+------------+ |  4 | approved |      1 |     4 | 2014-08-10 | +----+----------+--------+-------+------------+ 

edit: result week(date,3)...

select x.*    my_table x    left    join my_table y      on week(y.date,3) = week(x.date,3)     , y.status not in ('approved','pending')   y.id null; empty set (0.00 sec) 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -