0

I'm using SQL Server Compact.

To get a date without the time, I do this:

CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME);

To insert a new record, where the date is the smallest from another table, I do this:

INSERT INTO [Product] ([OrderDate], [Name]) 
SELECT TOP(1) [OrderDate], 'Widget' FROM [OtherProduct];

How do I combine those two ideas? I want something like this, but it doesn't work:

INSERT INTO [Product] ([OrderDate], [Name]) 
SELECT CAST(FLOOR(CAST(TOP(1) [OrderDate] AS FLOAT)) AS DATETIME), 'Widget' FROM [OtherProduct];

The error:

There was an error parsing the query. [ Token in error = TOP ]
h bob
  • 3,610
  • 3
  • 35
  • 51

1 Answers1

1

we have to specify TOP(1) on right place

INSERT INTO [Product] ([OrderDate], [Name]) 
SELECT TOP(1) CAST(FLOOR(CAST([OrderDate] AS FLOAT)) AS DATETIME), 'Widget' FROM [OtherProduct];
wiretext
  • 3,302
  • 14
  • 19