时间:2019-03-17 标签:c#Sqlstatement之间

发布于 2024-11-04 02:27:34 字数 459 浏览 1 评论 0原文

我正在尝试对客户账单进行排序,并且需要按不同时间段对它们进行排序。

我一直在尝试的是:

(select billing_date from [transaktions] 
 between '" + start + "' and '" +stop+"' where konto_nr = @konto_nr")

also

(select billing_date from [transaktions] where konto_nr = @konto_nr" between '" + start + "' and '" +stop+"')

start = 日期的开始时间段 stop = 周期结束

我收到的错误消息是

关键字附近的语法不正确 “之间”。

I'm trying to sort customers billings and i need to sort them by different time periods.

What I've been trying is:

(select billing_date from [transaktions] 
 between '" + start + "' and '" +stop+"' where konto_nr = @konto_nr")

also

(select billing_date from [transaktions] where konto_nr = @konto_nr" between '" + start + "' and '" +stop+"')

start = the starting period of the date
stop = the ending of the period

The error message I'm getting is

Incorrect syntax near the keyword
'between'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

兔姬 2024-11-11 02:27:34

首先:您不应该永远将 SQL 语句连接在一起!这为 SQL 注入攻击敞开了大门……

其次:您需要将 BETWEEN 子句放入 WHERE 子句中:

SELECT billing_date 
FROM dbo.[transaktions] 
WHERE Billing_Date BETWEEN @Start AND @EndDate
AND konto_nr = @konto_nr

First of all : you should never concatenate together your SQL statement! That's a big big open door for SQL injection attacks....

Second: you need to put your BETWEEN clause into a WHERE clause:

SELECT billing_date 
FROM dbo.[transaktions] 
WHERE Billing_Date BETWEEN @Start AND @EndDate
AND konto_nr = @konto_nr
若言繁花未落 2024-11-11 02:27:34

您的语法应该类似于

where Transaktions.Billing_Date between StartDate and EndDate

您正在使用的明显的相应列和变量名称。是的,您将“billing_date”引用为选定列,但 WHERE 可以测试条件的其他列,因此您也必须在那里明确标识它。

Your syntax should be something like

where Transaktions.Billing_Date between StartDate and EndDate

of the obvious respective columns and variable names you are working with. Yes, you referred to the "billing_date" as a selected column, but the WHERE can be testing OTHER columns of criteria so you have to explicitly identify it there too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文