Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Datefunction

Author  Topic 

wleonard
Starting Member

30 Posts

Posted - 2011-01-20 : 14:25:10
Hello. I am constructing my first program using Transact-SQL. My program is designed to work with 3 different database tables. The main table is the "Shipping_Promo_Date_Select" table. This table has two columns labeled "startdate" and "enddate". There is only one row in this table and it simply has a date. The first table is called "Shipping_Discount". This table is simply for a current promotion going on. The second table is called "Shipping_Discount_Future". This table is for a future promotion.

Now, using the Transact SQL function GETDATE (), I want to issue statements based on if the GETDATE () function matches the date on the "Shipping_Promo_Date_Select" table.

Any help would be greatly appreciated.

Will Leonard

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-20 : 14:57:17
[code]SELECT ...
FROM Shipping_Promo_Date_Select
WHERE DATEDIFF(day, getdate(), startdate) = 0[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-24 : 10:55:43
if there's an index on startdate use below instead

SELECT ...
FROM Shipping_Promo_Date_Select
WHERE startdate > = DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
AND startdate < DATEADD(dd,DATEDIFF(dd,0,GETDATE()),1)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -