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 2012 Forums
 Transact-SQL (2012)
 date

Author  Topic 

magmo
Aged Yak Warrior

558 Posts

Posted - 2015-04-10 : 04:09:31
Hi

I have a table that look like this..


USE [TestDB]
GO

/****** Object: Table [dbo].[OrderStatus] Script Date: 2015-04-10 10:01:20 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[OrderStatus](
[ID] [int] IDENTITY(1,1) NOT NULL,
[OrderID] [int] NULL,
[OrderName] [nvarchar](50) NULL,
[OrderStatusInfo] [nvarchar](4000) NULL,
[Customer] [nvarchar](255) NULL,
[SiteID] [int] NULL,
[ProviderID] [int] NULL,
[Delivered] [bit] NULL,
[DateDelivered] [datetime] NULL,
[OrderDate] [datetime] NULL,
CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO



I need to select all rows that meet the following requirement..

All rows that have "Delivered" as NULL or FALSE or
rows that have "Delivered" = TRUE AND "DateDelivered" is more than 2 Days ago.


Can anyone help me with that?




stepson
Aged Yak Warrior

545 Posts

Posted - 2015-04-10 : 05:14:34
[code]
SELECT *
FROM [dbo].[OrderStatus]
WHERE
([Delivered] IS NULL OR [Delivered] = 0)
OR
([Delivered] = 1 AND [DateDelivered] < DATEADD(day,-2,GETDATE()))
[/code]


sabinWeb MCP
Go to Top of Page

magmo
Aged Yak Warrior

558 Posts

Posted - 2015-04-10 : 05:33:29
Thanks, I got it now.
Go to Top of Page

stepson
Aged Yak Warrior

545 Posts

Posted - 2015-04-10 : 05:52:35
Great!


sabinWeb MCP
Go to Top of Page
   

- Advertisement -