开发者

c# Sql between statement

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 开发者_JS百科of the period

The error message I'm getting is

Incorrect syntax near the keyword 'between'.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜