从Tbl_Emp运行select DateOFJoin,其中SqlServer2005中DateOFJoin ='1/1/1990'当DateOFJoin的数据类型为nvarchar并选择日期时 [英] Run the select DateOFJoin from Tbl_Emp Where DateOFJoin ='1/1/1990' in Sql Server2005 When the datatype of DateOFJoin is nvarchar and select date

查看:109
本文介绍了从Tbl_Emp运行select DateOFJoin,其中SqlServer2005中DateOFJoin ='1/1/1990'当DateOFJoin的数据类型为nvarchar并选择日期时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Tbl_Emp运行select DateOFJoin,其中SqlServer2005中DateOFJoin ="1/1/1990"当DateOFJoin的数据类型为nvarchar并选择date

Run the select DateOFJoin from Tbl_Emp Where DateOFJoin =''1/1/1990'' in Sql Server2005 When the datatype of DateOFJoin is nvarchar and select date

推荐答案

您真的不应该将日期存储为NVARCHAR-这样总是很难进行比较.如果可以的话,请更改数据库以将DateOfJoin存储为Date或Date time,这样您就可以更轻松地进行数学运算.

但是,除此以外,您的查询应该可以工作(即使有点傻-它始终会返回您已经知道的数据:您在实际查询中正在测试的DateOfJoin字段.

我不确定您从"1/1/1990"那里获得的日期字符串不是正常" SQL日期,而是"1990-1-1",因为使用ISO是标准的使用SQL格式化yyyy-MM-dd.值得检查yo9u的来源,并确保其格式与DateOfJoin字段中的值相同.
You really shouldn''t store dates as NVARCHAR - it always makes comparisons like this difficult. If you can, change your database to store DateOfJoin as Date or Date time, and you can do math a lot more easily.

However, other than that your query should work (even if it is a little silly - it will always return data which you already know: the DateOfJoin field that you are testing in the actual query.

I''m not sure where you got your date string from ''1/1/1990'' is not a "normal" SQL date, that would be ''1990-1-1'' as it is standard to use ISO format yyyy-MM-dd with SQL. It would be worth checking where yo9u get it from, and makign sure it is the same format as the values in your DateOfJoin field.


请尝试以下操作:
Try the following:
select DateOFJoin from Tbl_Emp Where CONVERT(DATETIME,DateOFJoin,101) ='1/1/1990' 


这篇关于从Tbl_Emp运行select DateOFJoin,其中SqlServer2005中DateOFJoin ='1/1/1990'当DateOFJoin的数据类型为nvarchar并选择日期时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆