i want get all record which are saved by month 6 , all record saved by date.
my date Column datatype is ‘Date’ and named ‘Emissao’
month = 6 and year =2012;
query.Append(" SELECT NOTA,OPERADOR,EMISSAO,ORIGEM,TOTAL,ESPECIE,EMISSAO,HORA,DATA_IMPRESSAO,HORA_IMPRESSAO,CANCELADO ");
query.AppendFormat(" FROM VENDAS WHERE Month(EMISSAO)='{0}' and Year(EMISSAO)='{1}' ", Convert.ToInt32(month), Convert.ToInt32(year));
cmd.CommandText = query.ToString();
But I have Exception that ‘Tokan Unknown Month’ ?
Without magic indexing you’re likely better off doing an query such as:
Note the >= on the first part and the < on the second part. I only suggest this because it is (mostly) trivial to figure out the first of “next month” (need to catch the Dec/Jan detail) than it is to figure out the last day of a month.
But if you have utilities to give you that info quickly, that works fine to.
You want to do it this way because you can more easily leverage an index on the date. If you query by a component of the date, odds are very high you will table scan the table (typically not what you want), unless you do some special indexing.