473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Case statement insde where clause

ddtpmyra
333 100+
I'm trying to add my case statment inside the condition but I think I'm not doing this right. I want to run a list of orders based on current date.

Let say if current date is monday I want to run the added orders made from friday 3pm.

And if current date is tuesday then I want to run the orders added yesterday from 3pm.

Having this condition all I have to do is to play with the getdate and dateadd. Now I'm having problems in my case condition and it looks like this.

Expand|Select|Wrap|Line Numbers
  1. select * from orders
  2. where 
  3. CASE WHEN GETDATE()=DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0) --to get Monday
  4. THEN CONVERT(VARCHAR(10), DATEADD(D-3,GETDATE()), 121)+' 14:59:059.059' AND CONVERT(VARCHAR(10), GETDATE(), 121)+' 15:00:000.000'
  5. CASE WHEN  GETDATE()<>DATEADD(wk,DATEDIFF(wk,0,GETDATE()),0)
  6. THEN CONVERT(VARCHAR(10), DATEADD(D,-1,GETDATE()), 121)+' 14:59:059.059' AND CONVERT(VARCHAR(10), GETDATE(), 121)+' 15:00:000.000'
  7. END
=ORDER_CREATETIMESTAMP
Mar 1 '12 #1
1 1831
Rabbit
12,516 Expert Mod 8TB
It should be along the lines of this
Expand|Select|Wrap|Line Numbers
  1. CASE DATEPART(WEEKDAY, GETDATE())
  2. WHEN 2 THEN DATEADD(D, -3, GETDATE())
  3. ELSE DATEADD(D, -1, GETDATE()) END
Mar 2 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Largo SQL Tools | last post by:
Can anyone tell me if it's possible to use a Case statement in a Where clause, and if so, the proper syntax? J.R. Largo SQL Tools The Finest Collection of SQL Tools Available...
1
by: mirth | last post by:
I would like to update a decimal column in a temporary table based on a set of Glcodes from another table. I search for a set of codes and then want to sum the value for each row matching the...
3
by: Bryan | last post by:
I am executing a case statement list below, USE Northwind SELECT MONTH(OrderDate) AS OrderMonth, SUM(CASE YEAR(OrderDate) WHEN 1996 THEN 1 ELSE 0 END) AS c1996,
4
by: Chad Richardson | last post by:
I've always been mistified why you can't use a column alias in the group by clause (i.e. you have to re-iterate the entire expression in the group by clause after having already done it once in the...
2
by: Mark Mullins | last post by:
have code below: Function ClassColl(strClass As Variant, strColl As Variant) As String ' Comments : ' Parameters : strClass ' strColl ' Returns : String Description '...
9
by: paulmac106 | last post by:
If you could help me with my syntax i would really appreciate it. I'm trying to change the where clause on the fly, but it's giving me a syntax error. Hopefully from what I have below you can...
1
by: priyanka2203 | last post by:
Hi guys, I have a doubt regarding the CASE statement. It might sound silly, but me being new to DB2, it is kind of a genuine doubt. Try helping me with this.. When we use a case statement...
0
by: shipmen | last post by:
Hi all ! This is my first post here. I am totally new to db2 and last night I faced with this problem: I want to order my query results by different columns in ORDER BY clause using CASE...
2
by: pintu | last post by:
Hi Friends, I want to use "in" clause in case statement as shown below. e.g select * from employee where empid in case i_desgn when 'HR' then (1,2,3,4,5) when 'MD' then 1 else 7 end
2
by: Napsterr | last post by:
Following is the Code I am trying Declare @Day Int Set @Day=1 Select Mobile, Contact As Name, InTimeDay1 From uvw_UserDetails
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.