Pergunta

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

Foi útil?

Solução

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.

Outras dicas

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top