我有一个表格,有一栏的时日。 我想提出一个问题,选择该日所有各行。 基本情况
SELECT * FROM Table
WHERE [timeStamp] = 02-15-2003
但是,只有回归者,如果[当时的Stamp]是02-15-2003 00:00:000,但我真的想从那一天的某个时候赶走。
我有一个表格,有一栏的时日。 我想提出一个问题,选择该日所有各行。 基本情况
SELECT * FROM Table
WHERE [timeStamp] = 02-15-2003
但是,只有回归者,如果[当时的Stamp]是02-15-2003 00:00:000,但我真的想从那一天的某个时候赶走。
如果你有指数,你会想做一些没有阻止指数使用的东西:
SELECT *
FROM Table
WHERE [timeStamp] >= 20030215
AND [timeStamp] < 20030216
You can do a truncation operation on the [timeStamp]
column to get rid of any time part (implementation dependent), but this can potentially hurt the execution plan. Unfortunately, you really have to look at the execution plan to see this, because sometimes the optimizer is clever about some functions and sometimes it isn t.
如果你在2008年5月上台,你就应该到下台。
select * from [Table]
where cast([timeStamp] as date) = 02-15-2003
——————
评论者应在2012年回过来描述为什么这不是最佳解决办法:sargability。 改变WHERE条款中的数据类型,虽然这是最简单的解决办法,但对指数使用的影响是,经过约束的检索不会。
in sql server 2008 + :
SELECT * FROM Table
WHERE cast( [timeStamp] as date) = 02-15-2003
或
仅ZERO时间段:(2005年+)
SELECT * FROM Table
WHERE DateAdd(day, DateDiff(day, 0, [timeStamp]), 0) = 02-15-2003
《2014年行政法》是完美的:
SELECT [YourDateColumn] FROM [YourTable] WHERE(DATEPART(dd,[YourDateColumn]) = 29 )
雄厚的银有一些绩效问题。
这样做。 页: 1
SELECT * FROM Table WHERE convert(date,[timestamp]) = 2003-02-15
应于规定日期交还所有各行。
我将设立一个接受“启动日期”和“日期”的储存程序。
在这种情况下,起始日期和结束日期可以相同。
这确保了从12:01AM到11:59PM的所有各行都归还。
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE TestBetweenDates
-- Add the parameters for the stored procedure here
@StartDate DateTime = 0,
@EndDate DateTime = 0
AS
BEGIN
SET NOCOUNT ON;
SET @StartDate = cast(Convert(varchar(10), DateAdd(d, -6, @StartDate ), 101) + 12:01 AM as datetime)
SET @EndDate = cast(Convert(varchar(10), DateAdd(d, -0, @EndDate), 101) + 11:59 PM as datetime)
SELECT * FROM Table
WHERE ([timeStamp] BETWEEN @StartDate AND @EndDate)
END
GO
I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...
I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域
We have a restaurant table that has lat-long data for each row. We need to write a query that performs a search to find all restaurants within the provided radius e.g. 1 mile, 5 miles etc. We have ...
What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2
I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...
we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...
I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...
I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...