Some additional information on your data structure and requirements would help.
Assuming your data is in a table with a date and a value, e.g.:
table myTable (
theDate date,
theValue integer);
and you want to generate a result set with the sum of the values that fall within the given months, you could use:
select
jandata.total "Jan", febdata.total "Feb", mardata.total "Mar", aprdata.total "Apr", ...
from
(select sum(theValue) total from myTable where theDate >= '01/01/2009' and theDate < '02/01/2009') jandata,
(select sum(theValue) total from myTable where theDate >= '02/01/2009' and theDate < '03/01/2009') febdata,
(select sum(theValue) total from myTable where theDate >= '03/01/2009' and theDate < '04/01/2009') mardata,
...
This is brute force, but doesn't require any PL/SQL or unions.
(Above is in Transact-SQL, in Oracle you would need to cast the dates using the "to_date" function.)
Bizarre - why no union, which would make that trivial?
With those constraints, I think you are correct that the only solution is a table of month names.
From database table you access months in Data Table object
by using query
" SELECT * FROM tableMonth"
then catch in DataTable object of ADO.net
public DataTable SelectPeron(int Pid)
{
DataTable tab = new DataTable();
string Con = @"Data Source=sureit44;Initial Catalog=MydataBase;Persist Security Info=True;User ID=sitdev;Password=sitdev1";
using (SqlConnection con = new SqlConnection(Con))
{
string query="Select * FROM tableMonth";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
da.Fill(tab);
con.Close();
}
return tab;
After that Bind the tab object With DropDownList
ddl.DataSource=tab;
ddl.DataBind();
I think this will help you and u will get your d -zire result
Thanks
Hi guys !! =D I think I can finally can collaborate in a good manner =D. Check out this one:
SELECT TOP 12
DATENAME(MONTH, DATEADD(MONTH,ROW_NUMBER() OVER (ORDER BY object_id) - 1,0))
FROM sys.columns
Do you like it?
Discuss This Question: 8  Replies
table myTable ( theDate date, theValue integer);
and you want to generate a result set with the sum of the values that fall within the given months, you could use:select jandata.total "Jan", febdata.total "Feb", mardata.total "Mar", aprdata.total "Apr", ... from (select sum(theValue) total from myTable where theDate >= '01/01/2009' and theDate < '02/01/2009') jandata, (select sum(theValue) total from myTable where theDate >= '02/01/2009' and theDate < '03/01/2009') febdata, (select sum(theValue) total from myTable where theDate >= '03/01/2009' and theDate < '04/01/2009') mardata, ...
This is brute force, but doesn't require any PL/SQL or unions. (Above is in Transact-SQL, in Oracle you would need to cast the dates using the "to_date" function.)DataTable tab = new DataTable(); string Con = @"Data Source=sureit44;Initial Catalog=MydataBase;Persist Security Info=True;User ID=sitdev;Password=sitdev1"; using (SqlConnection con = new SqlConnection(Con)) { string query="Select * FROM tableMonth"; SqlCommand cmd = new SqlCommand(query, con); con.Open(); using (SqlDataAdapter da = new SqlDataAdapter(cmd)) da.Fill(tab); con.Close();
} return tab; After that Bind the tab object With DropDownListSELECT TOP 12 DATENAME(MONTH, DATEADD(MONTH,ROW_NUMBER() OVER (ORDER BY object_id) - 1,0)) FROM sys.columns
Do you like it?