1

I have this table:

CREATE TABLE [dbo].[Phrase] (
    [PhraseId]     UNIQUEIDENTIFIER DEFAULT (newid()) NOT NULL,
    [English]      NVARCHAR (250)   NOT NULL,
    [CreatedDate]  DATETIME         DEFAULT (getdate()) NOT NULL,
    [ModifiedDate] DATETIME         DEFAULT (getdate()) NOT NULL,
    PRIMARY KEY CLUSTERED ([PhraseId] ASC)
);

What I need to do is a simple select * but I am not sure how to enter in the select where clause criteria. Would appreciate any suggestions.

  • 1
    What about the `WHERE` clause do you not understand? – Gordon Linoff Feb 01 '17 at 13:10
  • Please clarify "in last two days" as either "any time on a datetime from the date two days ago" OR "48 hours from the current time" this varies the query. – Mark Schultheiss Feb 01 '17 at 13:14
  • Possible duplicate of [How to get last 7 days data from current datetime to last 7 days in sql server](http://stackoverflow.com/questions/27599557/how-to-get-last-7-days-data-from-current-datetime-to-last-7-days-in-sql-server) - note just change the query to 2 instead of 7 in that question perhaps? Another possibility: http://stackoverflow.com/questions/1503298/sql-statement-to-select-all-rows-from-previous-day – Mark Schultheiss Feb 01 '17 at 13:17

2 Answers2

0

First you define what "2 days ago" is:

DATEADD(DAY, -2, GETDATE())

Note that this includes the time component.

Since you always set the ModifiedDate with a DEFAULT value, we only need to check that column:

WHERE ModifiedDate >= DATEADD(DAY, -2, GETDATE())
DavidG
  • 113,891
  • 12
  • 217
  • 223
0

You can use this selection:

SELECT *
FROM Phrase
WHERE createddate >= dateadd(day,-2,getdate())
Aya Aboud
  • 371
  • 2
  • 4
  • 16