DataSource Controls :: Use SQL GROUP BY Statement To Create Menu?
Jan 27, 2010
I'm trying to create a menu structure, subpages within pages, for use with my cms. I have 3 tables in sql server, I would like to query all three tables and list those pages with a certain siteid, and subpages where the subid is the pageid. how to use the GROUP BY Statement to create the menu below? Or could I use vb.net to display it for me? Something like this:
SELECT * FROM sites
LEFT JOIN pages ON sites.siteid=pages.siteid
LEFT JOIN subpages ON pages.pageid=subpages.pageid
WHERE sites.siteID = 1ORDER BY sites.siteid, pages.pagesub ASC
These are my tables:
siteID int Unchecked PK
siteName nvarchar(MAX) Checked
siteAdmin nvarchar(MAX) Checked
siteLive bit Checked
pageID int Unchecked PK
siteID int Checked FK linked to siteid in sites table
pageLink nvarchar(MAX) Checked
pageBody ntext Checked
pageSummary ntext Checked
pageTitle ntext Checked
pageOrder int Checked
pageHome bit Checked
subID int Unchecked PK
PageID int Checked FK linked to pageid in pages table
subBody ntext Checked
subSummary ntext Checked
subTitle nvarchar(MAX) Checked
subOrder nvarchar(MAX) Checked
i have a form view that takes fields from two tables 'Contract' and 'volunteers', however because i used a query builder,i have to input an insert statement. How do i create an insert statement for two tables in one query?
I am trying to create a multi column listbox by combining fields in Linq select statement, as Let Name = Last + First. The problem is how to pad the Last column with spaces as you would in SQL using REPLICATE so when I bind the listbox to the data, it looks like two columns.
i have to Count Data Month wise and Date format would be like this Feb-10 and iam using the below query but no luck .
SELECT REPLACE(CONVERT(CHAR(9), ADate, 6), ' ', '-') As 'MonthYear', COUNT(AID) AS 'Planned' FROM Employee where Status =1 and YEAR(Adate) = '2009' GROUP BY YEAR(Adate), MONTH(Adate) ORDER BY YEAR(Adate),MONTH(Adate)
SELECT documentcategoryname, documentname, documentid FROM documents INNER JOIN documentcategory ON documents.documentcat = documentcategory.documentcategoryid WHERE documentsiteid = @siteid GROUP BY documentcategoryname, documentname, documentid
Which gives the following results:
documentcategoryname | documentname | documentid About Us doccy3 3 About Us doccy4 4 Map Of Medicine doccy5 5
Is there a way using vb.net I can just display the category name once, and the documents underneath it like below:
About Us doccy3 doccy4 Map Of MEdicine doccy5
My code so far is:
If pagesreader.Read() Then ' output documentcategoryname mydata &= "<h2>" & reader.Item("documentcategoryname") & "</h2>" 'display document list here using while loop? End if
I've written this code to display a group of events when the value is 12/19/2010. This means each day I need to change the "default value" to the current date to display the events of the day. I would like to make this such that the change occurs automatically, that is, on 12/20/2010, I'd like to see just the events for 12/20/2010.
I'm attempting to further reduce a dataset/table by various user input. Part of this process is grouping the data by a timestamp prior to a summation. I'm trying to use LINQ and cannot get the data returned that I need.
I have some duplication that I need to clean up. I wrote a SQL query that is supposed to return duplicate customers who are located in the same city and zipcode.
I have 2 questions regarding it:
1. Is the query syntax correct to find duplicate records by same city and zipcode, data is being returned but it just returns the same customer a few times?
2. I only need to do the GROUP BY clause for Fullname and City however it gives an error when the other columns are left out. The error is Address, State and Zip not being in the aggregate function or in the group by clause.
Adding all the remaining columns to the GROUP BY clause works.
What i need to do is select the last 5 events for each group using LINQ to Objects. I tried starting with:
But i'm not sure how i only take the last 5 per group.
The simple way of doing this is to get the groups and then have a property on that which returns the last 5 events but if i databind this i will have to use a nested Repeater/ListView. Ideally i would like to have a row foreach event.
select r.Name,c.Name,s.Name,(select count(p1.id)from profiles p1 where r.id=p1.religion and c.id=p1.caste and s.id=p1.subcaste and p1.Gender=1)as Male,(select count(p1.id)from profiles p1 where r.id=p1.religion and c.id=p1.caste and s.id=p1.subcaste and p1.Gender=2)as Female from religion r,profiles p,caste c,subcaste s where r.id=p.religion and c.id=p.caste and s.id=p.subcaste group by r.Name,c.Name,s.Name,r.id,c.id,s.id
I have a table that contains image data type and has more than 20,000 records.I want to change its file group to the new file group. I tried to change it using table designer, but everytime I wanted to save it, it occured an error with this message:
Does anyone know how to change file group using Alter Table query? I'm using SQL Server 2005.
I am writing a simple form that will take in data and insert it into a db if it's a new record and update the existing record if it already exists. The insert works fine, but the update isn't working at all, yet the code looks solid to me and everything I've compared it to in my google searches.
I've done some SSIS package work in the past, but am by no means an expert.
I want to use an SSIS package to do the following:
1. Get the file name of the newest file in a windows folder (using a filename template like his: filename_ *.txt where the * part is always a date in the format of yyyy-mm-dd.
2. Use that file name in later portions of the SSIS package by reading the file and transferring data from it to a SQL table using a Data Flow task.
and use the result (which should be the name of the newest file) to open that file and pull data out of it and into a 2nd SQL table. I admit, I'm not sure how to use the dynamic result of this SELECT query as the file name in a flat file connection manager.