我尝试过查询但显示错误 [英] I tried query but shows error

查看:150
本文介绍了我尝试过查询但显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子如下



select * from plandate



Fromdate Todate
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)



当我执行以上查询我得到如下错误



必须声明标量变量@fromdate

i have one table as follows

select * from plandate

Fromdate Todate
2017-03-02 2017-03-08


i 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 as

03/06/2017
04/06/2017
05/06/2017
06/06/2017
07/06/2017


for getting a above output i tried my below query as follows

SELECT * FROM Plandate
WHERE 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 follows

Must 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-08


i 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 as

03/06/2017
04/06/2017
05/06/2017
06/06/2017
07/06/2017


for getting a above output i tried my below query as follows

SELECT * FROM Plandate
WHERE 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 follows

Must 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.


这篇关于我尝试过查询但显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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