How do I check if the current time is between two times in SQL?

Viewed 21141

This isn't working:

IF EXISTS (( SELECT  1
            FROM    dbo.SalesOrder )
   AND (GETDATE() BETWEEN '07:00:00' AND '16:00:00'))
   BEGIN
         PRINT 'yes!'
   END

I want to do:

If something exists in the SalesOrder table AND the current time is between 7am and 4pm, then print 'YES'

I'm assuming I might have to do a conversion there but I'm unsure on how to do it properly.

Anyone care to give me a hand?

2 Answers
Related