SQL Server:在日期文字中使用#

时间:2022-05-27 08:27:22

In W3School, I found the below code in SQL section.

在W3School中,我在SQL部分找到了以下代码。

SELECT * 
FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;

I know we specify single quote for the date string like '07/04/1996'.

我知道我们为日期字符串指定单引号,如'07 / 04/1996'。

Can we also use # for the date string ? Does use of # has some significance?

我们还可以使用#作为日期字符串吗?使用#有一些意义吗?

1 个解决方案

#1


1  

Not valid SQL Server syntax:

无效的SQL Server语法:

with Orders as (
    select CURRENT_TIMESTAMP as OrderDay
)
SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;

Incorrect syntax near '#'.

'#'附近的语法不正确。

The website does not mention anything about SQL Server by the way.

该网站没有提及任何有关SQL Server的信息。

As per @marc_s' comment, this might be valid MS Access SQL syntax.

根据@marc_s的注释,这可能是有效的MS Access SQL语法。

#1


1  

Not valid SQL Server syntax:

无效的SQL Server语法:

with Orders as (
    select CURRENT_TIMESTAMP as OrderDay
)
SELECT * FROM Orders
WHERE OrderDate BETWEEN #07/04/1996# AND #07/09/1996#;

Incorrect syntax near '#'.

'#'附近的语法不正确。

The website does not mention anything about SQL Server by the way.

该网站没有提及任何有关SQL Server的信息。

As per @marc_s' comment, this might be valid MS Access SQL syntax.

根据@marc_s的注释,这可能是有效的MS Access SQL语法。