[数据库]日期格式相关参数传递
也许是我忘记了吧,反正这一切让我感觉如此新鲜,赶快写下来~
今天要向数据库传递一个日期格式的值,但却发现不知道如何传递日期参数进去
数据库里该字段是以日期格式存储的,而平时写selcet一般都是处理字符串型和数值型的数据,很少涉及日期型(很久没写代码了,都忘记差不多了~)
想了好多办法啊,不过还好没去尝试,因为办法都给人以好长且效率好低的感觉。日期型用字符串是无法传递的了,+号无法重载该类型的值。还想了把值提取出来做判断,这样一算,这个读取次数从n变成了2n了~~~~效率又低了,汗掉~~~~~~~~
还好问了个同学,“#”,多神奇的字符,直接把字符串型当作日期型就摆平了。
strSQL="delete from Attendance where PERSON_ID='"+m_cList.GetItemText(nItem,1)+"' and IO_TIME=#"+strTime+"#";
让我记下这个开心的想法,虽然感觉好像以前数据库书上有念到过~~~~~嗨,知识遗忘厉害。惭愧
2007-4-11:
今天发现在SQLServer2005里面应该不是用'#'还是使用 ' 符号
下面是对Northwind的查询语句
查询1996-07-04到1996-07-09之间的数据
SELECT [OrderID]
,[CustomerID]
,[EmployeeID]
,[OrderDate]
,[RequiredDate]
,[ShippedDate]
,[ShipVia]
,[Freight]
,[ShipName]
,[ShipAddress]
,[ShipCity]
,[ShipRegion]
,[ShipPostalCode]
,[ShipCountry]
FROM [Northwind].[dbo].[Orders]
where OrderDate > '1996-07-04'
and OrderDate < '1996-07-09'
如果使用#会怎么样呢?
消息 102,级别 15,状态 1,第 16 行
'#' 附近有语法错误。
今天要向数据库传递一个日期格式的值,但却发现不知道如何传递日期参数进去
数据库里该字段是以日期格式存储的,而平时写selcet一般都是处理字符串型和数值型的数据,很少涉及日期型(很久没写代码了,都忘记差不多了~)
想了好多办法啊,不过还好没去尝试,因为办法都给人以好长且效率好低的感觉。日期型用字符串是无法传递的了,+号无法重载该类型的值。还想了把值提取出来做判断,这样一算,这个读取次数从n变成了2n了~~~~效率又低了,汗掉~~~~~~~~
还好问了个同学,“#”,多神奇的字符,直接把字符串型当作日期型就摆平了。
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2007-4-11:
今天发现在SQLServer2005里面应该不是用'#'还是使用 ' 符号
下面是对Northwind的查询语句
查询1996-07-04到1996-07-09之间的数据
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
如果使用#会怎么样呢?
--错误代码 Error Code
1
SELECT [OrderID]
2
,[CustomerID]
3
,[EmployeeID]
4
,[OrderDate]
5
,[RequiredDate]
6
,[ShippedDate]
7
,[ShipVia]
8
,[Freight]
9
,[ShipName]
10
,[ShipAddress]
11
,[ShipCity]
12
,[ShipRegion]
13
,[ShipPostalCode]
14
,[ShipCountry]
15
FROM [Northwind].[dbo].[Orders]
16
where OrderDate > #1996-07-04#
17
and OrderDate < #1996-07-09#
18![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
1
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
4
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
7
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
8
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
9
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
10
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
13
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
14
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
15
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
16
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
17
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
18
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
消息 102,级别 15,状态 1,第 16 行
'#' 附近有语法错误。
posted on 2006-12-02 15:07 volnet(可以叫我大V) 阅读(964) 评论(1) 编辑 收藏 举报