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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 date depentend select

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-05-16 : 00:59:16
Hi

I have this Query..


SELECT TOP (100) PERCENT NodeId, ParentNodeId, Text, ImageUrl, NavigateUrl, Active, CustID, ProductInformation, StartDate, EndDate, DateEnabled
FROM dbo.tbl_Products
WHERE (CustID = 2) AND (Active = 1) AND (ShowItem = 1 OR ShowItem IS NULL)
ORDER BY Text, NavigateUrl



I would like to add the following. If DateEnabled not is null and also is True I would like to check weather the startdate and enddate is between the current date, if its not it shouldnät be displayed but if it is display it. Can someone show me how?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-05-16 : 01:02:58
[code]AND (
DateEnabled IS NULL
OR (startDate <= GETDATE() AND EndDate >= GETDATE())
)[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2014-05-16 : 01:20:58
Thank you, worked perfect
Go to Top of Page
   

- Advertisement -