i am developing a account statement so when the user click on the link to view the February link it will show the transaction from Jan - Feb ,
how to format it to a query
i have the sample fo the following table:
ID trans_desc trans_date
-------------
1 testing 1/9/2003 11:33:00 AM
2 testing1 2/9/2003 11:33:00 AM
3 testing2 1/9/2004 11:33:00 AM
how to i extract the transaction description month from the month Jan-Feb . how to i do for the SQL queryIf there are 50 people on this forum, you'll get 50 different ways to do this. Here is one:
declare @.SelectedDate datetime
set @.SelectedDate = '2003-02-15'
select *
from YourTable
where trans_date >= convert(char(4), @.SelectedDate, 120)+'-01-01'
and trans_date < dateadd(month, 1, convert(char(7), @.SelectedDate, 120)+'-01')
No comments:
Post a Comment