2017-03-02 2017-03-08 i希望在日期和日期之间显示使用上面两个表的日期。 如何编写sql server查询。 i希望输出为 03/06/2017 04/06/2017 / 05/06 06/06/2017 我尝试了以下查询,如下所示 SELECT * FROM Plandate WHERE CONVERT( VARCHAR,date,111)> = CONVERT(VARCHAR,@ Fromdate,111) 和CONVERT(VARCHAR,date,111)< = CONVERT(VARCHAR,@ Todate,111) 当我执行上述查询时我得到如下错误 必须声明标量变量@fromdate 我尝试了什么: i有一张桌子如下 select * from plandate Fromdate Todate 2017-03-02 2017-03-08 i希望使用上面两张表显示日期和日期之间的日期。 表示如何编写sql server查询。 i想要输出为 /> 03/06/2017 05/06/2017 06 / 06/2017 07/06/2017 获得以上输出我尝试了以下查询如下 SELECT * FROM Plandate WHERE CONVERT(VARCHAR,date,111)> = CONVERT(VARCHAR,@ Fromdate,111 ) 和CONVERT(VARCHAR,date,111)< = CONVERT(VARCHAR,@ Todate,111) 当我执行以上查询我得到如下错误 必须声明标量变量@fromdatei have one table as follows select * from plandate Fromdate Todate 2017-03-02 2017-03-08i want to display in between those date from date and to date using above two table.for that how to write the sql server query.i want the output as03/06/201704/06/201705/06/201706/06/201707/06/2017for getting a above output i tried my below query as followsSELECT * FROM PlandateWHERE CONVERT(VARCHAR,date, 111) >=CONVERT(VARCHAR,@Fromdate,111)And CONVERT(VARCHAR,date, 111) <=CONVERT(VARCHAR,@Todate,111)when i execute the above query i get error as followsMust declare the scalar variable "@fromdate"What I have tried:i have one table as follows select * from plandate Fromdate Todate 2017-03-02 2017-03-08i want to display in between those date from date and to date using above two table.for that how to write the sql server query.i want the output as03/06/201704/06/201705/06/201706/06/201707/06/2017for getting a above output i tried my below query as followsSELECT * FROM PlandateWHERE CONVERT(VARCHAR,date, 111) >=CONVERT(VARCHAR,@Fromdate,111)And CONVERT(VARCHAR,date, 111) <=CONVERT(VARCHAR,@Todate,111)when i execute the above query i get error as followsMust declare the scalar variable "@fromdate"推荐答案检查 @Fromdate 和 @Totate : 它们是什么? 它们来自哪里? 如果它们是paprmeters,你必须声明它们。 看起来像 date , @Fromdate 和 @Totate 在开头是datetime数据类型,为什么在比较前转换它们? 提供此查询的人应该知道错误的原因。Check @Fromdate and @Todate:what are they ?Where are they coming from ?If they are paprmeters, you must declare them.Looks like date, @Fromdate and @Todate are datetime datatype in the beginning, why do you convert them before comparing ?The person who gave you this query should know the why of the error. 这篇关于我尝试过查询但显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 14:11
查看更多