473,505 Members | 13,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IF THEN statement in WHERE clause???

137 New Member
Hello,
I'm trying to select a dayvalue in the sql statement depending on the openingstime.

So if the shop opens on 8:00 and the time is before that i want to show the times that it's open today.
If the actual time is after closing time i want to show the openingstime for the next day.
This is where i came so far...:
Expand|Select|Wrap|Line Numbers
  1. SELECT customer_id, day_number,
  2.   start_time_hour   = ( start_time / 3600 ),
  3.   start_time_minute = floor((( start_time / 3600.0 ) - ( start_time / 3600 )) * 60 ),
  4.   end_time_hour     = ( end_time / 3600 ),
  5.   end_time_minute   = floor((( end_time / 3600.0 ) - ( end_time / 3600 )) * 60 )
  6. FROM office_hours WITH( NOLOCK) 
  7. WHERE customer_id = 28 
  8. AND IF (SELECT DATEPART(hour, GETDATE())) > start_time
  9.           BEGIN (day_number = (DATEPART(dw, GETDATE()+1) + 6) % 7) 
  10.          END
  11.          ELSE
  12.          BEGIN
  13.           (day_number = (DATEPART(dw, GETDATE()) + 6) % 7) 
  14.          END
  15. ORDER BY day_number, start_time_hour, start_time_minute
Is this possible or do i have to try it on a different way?

Thanks!
Regards,
Paul
Dec 30 '08 #1
1 2567
debasisdas
8,127 Recognized Expert Expert
you need to use CASE for the purpose.

eg.
Expand|Select|Wrap|Line Numbers
  1. Select [id],[Full Name] = case Gender
  2.  when 'M' then 'Mr. '+[First name]+ ' '+[Last name] 
  3.  when 'F' then 'Ms. '+[First name]+ ' '+[Last name] 
  4.  end
  5. from Emp
  6.  
Dec 30 '08 #2

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

Similar topics

7
3490
by: Guy Hocking | last post by:
Hi there, I have a problem in my ASP/SQL Server application i am developing, i hope you guys can help. I have a ASP form with list boxes populated by SQL tables. When a user selects a value...
3
17352
by: Robby McGehee | last post by:
I need this to work: SELECT FROM WITH (NOLOCK) where ='a' GROUP BY , HAVING COUNT () > 1 The problem is that I get an error that needs to be in the GROUP BY clause or aggregate function. if...
4
28811
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...
1
4461
by: brett | last post by:
Here is my SQL string: "SELECT to_ordnum, to_orddate," _ & "(SELECT SUM((DDPROD.pr_stanmat * DDPROD.pr_prfact) * (DOBOM2.b2_quant * DDORD.or_quant)) FROM DDPROD INNER JOIN DOBOM2 ON...
2
2502
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
4
25573
by: Tom Walker | last post by:
I cannot get the WHERE statement to work correctly unless I use a literal with the LIKE. I want to use a working storage data name so that I can vary the WHERE statement. Example that works: ...
7
11417
by: mark | last post by:
Access 2000: I creating a report that has a record source built by the user who selects the WHERE values. An example is: SELECT * FROM CHARGELOG WHERE STDATE Between #10/27/2003# And...
6
7642
by: BerkshireGuy | last post by:
Does anyone know of a good function that will parse out parts of an SQL statement that is passed to it in seperate variables? It should be able to parse statements that contain ORDERBY, WHERE,...
9
2349
by: Michael | last post by:
Hi all, I would like to get people's opinion about executing SQL statements in C# (or any other .NET language really). I used to create my SQL statement by building a string and replacing single...
2
544
by: iulian.ilea | last post by:
What is wrong int this SQL statement? select top 10 DOCInt.*, DOCDet.* , Cate.*, Arti.*, .* from DOCInt INNER JOIN DOCDet ON DOCInt.CodDoc=DOCDet.CodDoc LEFT JOIN Cate ON...
0
7213
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
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.