asp.net - How to match only month and year part from datetime column in SQL Server -


i have 2 inputs, month , year.

  selectedmonth = ddlmonth.selecteditem.value;//1   selectedyear = ddlyear.selecteditem.text.trim();//2013 

i want show records preset or not of particular month , year instead of date. want show registered employee

sql query

select e.enquiryid, registrationnumber, name branch b     left join enq e on b.enqui = e.enqu reg = @regno   , pay=cheque  

i need if selected month =1 ad year=2015. if present in payment date , cheque. like:

where registratio = @regno   , payment(month) = selectedmonth   , payment(year) = selectedyear   , chequere(month) = selected month   , chequere(year) = selected year 

my columns chequere , payment date in datetime format.

the efficient way construct date within application code:

selectedmonth = ddlmonth.selecteditem.value;//1 selectedyear = ddlyear.selecteditem.text.trim();//2013    var date = new datetime(int.parse(selectedyear), int.parse(selectedmonth), 1); 

then pass date parameter query:

where registrationnumber = @regno   , paymentdate >= @date   , paymentdate < dateadd(month, 1, @date)   , chequereceiveddate >= @date   , chequerecieveddate < dateadd(month, 1, @date); 

this makes query sargable, , means don't need perform datepart() functions on columns.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -