Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want get current selected month dropdown(september) this month get previous month data in Asp.net with C# or sql server


Below code I am using but result was not came

Sql Query:

select substring(DATENAME(MONTH, ProcessDate),1,3) as Month from Accounts_DailyAttendance where datename(MONTH,ProcessDate)='September'

The above query wise data get wrong, so i want correct data.

i want result is October month data

Thanks
Posted
Updated 6-Dec-14 2:24am
v2
Comments
Maciej Los 6-Dec-14 8:25am    
What exactly problem do you have?
Nirmal Chandru 6-Dec-14 8:39am    
I want Current month selected get last month record
ex:
Dropdown selected "September" so i want result is "october" month Record
Masud Ahmed SQL Programmar 6-Dec-14 21:32pm    
So, you want to select September from the DropDown box, and you want to see the result for October month? It means you want to see the next month result not the last month, am I right?

Try below
SQL
select 
    substring(DATENAME(MONTH, ProcessDate),1,3) as Month 
from 
    Accounts_DailyAttendance 
where 
    datename(MONTH,DateAdd(mm,-1,ProcessDate))='September'
 
Share this answer
 
v3
Hi,
try this
SQL
select
    substring(DATENAME(MONTH, ProcessDate),1,3) as Month
from
    Accounts_DailyAttendance
where


Month(ProcessDate)=DateAdd(mm,1,convert(date,'1/'+ cast(DATEPART(MM,'September', year(getdate())) as char(2))+'/'+ cast(year(getdate()) as char(4)),103))
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900