SQL 语句求教
通过SQL查询数据库 通过当天日期对比来查询出当天注册的用户的数据记录
menber_reg_Time 是 SQL server数据库里的一个datetime字段, 数据是这样的格式:2011-11-09 14:25:17
SQL code
1."select * from nob2b_users where datediff(day,'menber_reg_Time',getdate())=0 Order By menber_reg_Time desc";
"//错误提示:从字符串转换为 datetime 时发生语法错误。"
2. "select * from nob2b_users where datediff(day," + Convert.ToDateTime("'menber_reg_Time'")+ ",getdate())=0 Order By menber_reg_Time desc";
"//错误提示:从字符串转换为 datetime 时发生语法错误。"
请教错误在哪里?要怎么改?
谢谢
------解决方案-------------------- 1."select * from nob2b_users where datediff(day,'menber_reg_Time',getdate())=0 Order By menber_reg_Time desc";
"//错误提示:从字符串转换为 datetime 时发生语法错误。"
去掉时间字段两端的单引号
"select * from nob2b_users where datediff(day,menber_reg_Time,getdate())=0 Order By menber_reg_Time desc";
2. "select * from nob2b_users where datediff(day," + Convert.ToDateTime("'menber_reg_Time'")+ ",getdate())=0 Order By menber_reg_Time desc";
"//错误提示:从字符串转换为 datetime 时发生语法错误。"
"select * from nob2b_users where datediff(day,menber_reg_Time,getdate())=0 Order By menber_reg_Time desc";
------解决方案--------------------menber_reg_Time 没有一对单引号时是列名,有了单引号就变成字符串常量了