Ascending Categories And Ascended Subcategories
Apr 18, 2014
I've been trying some examples on line and have not been able to get this to work.
Here is my table followed by what I am trying to output.
Id | ParentId | CategoryName
33 | 0 | Fruits
34 | 0 | Vegetables
35 | 0 | Meats
37 | 33 | Grapes
38 | 33 | Oranges
[Code] ....
I want to output this for a dropdownlist in C# with ascending categories and ascended subcategories
48 0 Electronics
33 0Fruits
3933 -Apples
4033 -Bananas
3733 -Grapes
3833 -Oranges
[Code] ...
This is what I have currently, still a long way off :/
SELECT TOP (100) PERCENT fcat.Id AS fcat_id, fcat.CategoryName AS fcat_name, fcat.ParentCategory AS fcat_parent, fsub.Id AS fsub_id,
fsub.CategoryName AS fsub_name, fsub.ParentCategory AS fsub_parent
FROM dbo.ProductCategories AS fcat LEFT OUTER JOIN
dbo.ProductCategories AS fsub ON fcat.Id = fsub.ParentCategory
ORDER BY fcat_name, fcat_id, fsub_name
View 2 Replies
ADVERTISEMENT
May 1, 2006
Hi, I have a database that will have various categories:
take this:
Kids:Boys Collection:Children Boys Collection:Children Boys Athletic:Athletic - Canvas
(it's shoes)
I have to put that in a structure that makes sense. I don't think having several tables for categories, subcategories, subsubcategories.... is the right way to do it. I'm not a design expert, so I was hoping someone might help me. How can I organize this? Any book, link, or advice is appreciated. Thank you.
View 7 Replies
View Related
Dec 17, 2006
Hi, I Have 2 tables. First name of this tables is news_categories with one record: News. Strucutre this table ID and name_categories Second name of this tables is news_subkategorie with two records : With country and with world. Strucutre ID_Subcategories and name_subcategories I will receve effects:
News
--With country
--With world
How i write in Select Command ?
SELECT [ID_subcategries], [Name_subcategories], [ID] FROM [db_subcategories], [db_categories] WHERE (??)
View 1 Replies
View Related
Dec 17, 2006
Hi, I Have 2 tables. First name of this tables is news_categories with one record: News. Strucutre this table ID and name_categories Second name of this tables is news_subkategorie with two records : With country and with world. Strucutre ID_Subcategories and name_subcategories I will receve effects:
News
--With country
--With world
How i write in Select Command ?
SELECT [ID_subcategries], [Name_subcategories], [ID] FROM [db_subcategories], [db_categories] WHERE (??)
View 4 Replies
View Related
Jan 18, 2012
I have a table Category whose structure is as follows:
id
name
parentid
So i have number of nodes from the root of a specific category. How to get all the sub categories(ie nodes) for all parent categories?
View 14 Replies
View Related
Aug 9, 2007
I have an application which has a database table called Category. Its very simple, with fields id and categoryname.
My client now wants functionality for sub categories. Whats the best way to do this. My initial thought was to keep the same database table but have a 3rd column called ParentID which contains the ID of the parent category.
Is this the best way? Or something else.
Thanks
View 2 Replies
View Related
Mar 30, 2008
I have two tables, one is a list of categories, the other a list of items listed in the categories. The category table is self-referencing through a ParentID column. Top-level categories have ParentID = 0.
Categories========ID intParentID intCatName varchar(30)Items====IDCategoryIDItemID
There is a third table that links to items through ItemID, but this is not important for this problem!
What I want to do is create a stored SQL procedure. This procedure simply pulls rows from the category table and counts the number of items that are in it. This is straighforward enough using COUNT as a "virtual column", but the difficulty is counting the items in the category but also the items in any subcategories.
An end result with two top-level categories and three subcategories in each might look like:
- Category 1 (20)---- Subcategory 1.1 (10)---- Subcategory 1.2 (5)---- Subcategory 1.3 (5)- Category 2 (14)---- Subcategory 2.1 (3)---- Subcategory 2.2 (4)---- Subcategory 2.3 (7)Hence the difficult bit is getting the total number in brackets for each category with subcategories.
What I have at the moment is:
SELECT Categories.ID, Categories.CategoryName, Categories.ParentID, (SELECT COUNT(*) FROM Items WHERE Items.CategoryID = Categories.ID) AS ItemTotalFROM Categories
What I would like is something along the lines of (pseudocode):
SELECT Categories.ID, Categories.CategoryName, Categories.ParentID, (SELECT COUNT(*) FROM Items WHERE <Item is in category or subcategory>) AS ItemTotalFROM Categories
I don't particularly want to use temporary tables and I definitely do not want to do any of this retrieval in my application - it needs to come straight from the database.
Thanks!
View 2 Replies
View Related
Jul 23, 2005
Below is the statement i am working with and i am trying to figure outhow to have the count in ascending order...is this possible? Right nowit groups by FP in alphabetical order but i dont want that i want thewhatever the FP1 count is to be ascending but i am not sure how to goabout doing this...so any help or ideas?SELECT FP1 AS FP, COUNT(FP1) AS Expr1FROM dbo.FP1WHERE (FP1 IS NOT NULL) AND (LTRIM(RTRIM(FP1)) <> '')GROUP BY FP1
View 3 Replies
View Related
May 20, 2008
Hi,
have uncovered a curious problem with sort ascending in tables.
In a table I'm grouping on CONTRACT_ID field. The grouping works fine but the sort acending on CONTRACT_ID doesn't.
Here are the actual contract id's I have to sort:
0202018B
0202019C
0202020G
0202021H
0202022J
0202023K
0202800B
The above list is how the Crystal Report I'm converting does this sort - i.e. the normal, common sense, intuitive answer.
Here's how SSRS does the sort:
0202022J
0202021H
0202019C
0202800B
0202018B
0202023K
0202020G
i.e. a completely non-intuitive, non common-sense answer!
I can probably solve this by stripping the last character and converting to int via an expression, but why does one get a completely non-sensical answer with the standard values? What is the logic by which Microsoft have implemented sorting. It seems very odd to me. Can anyone shed any light on this?
thanking you in advance,
cheers,
rob
View 3 Replies
View Related
Apr 16, 2008
Currently I have a small page that includes a drop down list with about 120 possible choices to chose from.
The list works fine, however, the choices are not sorted ascending/alphabetical order. So it is very slow searching for
the selection you want.
See the link.
http://visualboxscore.com/boxscores/cfb_box_scores.aspx
Does anyone have any easy solution for this problem?
Below is the code I am using.
<%@ Page Language="VB" %>
<html>
<head id="Head1" runat="server">
<title>Visualboxscore.com - College Football Box score Query page</title>
</head>
<body>
<form id="form1" runat="server">
<b>Select Team:</b>
<asp:DropDownList ID="DropDownList1" DataSourceID="SqlDataSource2" AutoPostBack="true"
DataTextField="offense" runat="server" />
<asp:SqlDataSource ID="SqlDataSource2" runat="server" SelectCommand="SELECT DISTINCT [offense] FROM [cfb_boxscores]"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" />
<br />
<br />
<table>
<tr>
<td valign="top">
<asp:GridView ID="GridView1" AllowSorting="True" AllowPaging="false" runat="server"
DataSourceID="SqlDataSource1" DataKeyNames="date"
AutoGenerateColumns="false" Width="427px">
<Columns>
<asp:BoundField HeaderText="Date" DataField="date" DataFormatString="{0:MM/dd/yy}" ItemStyle-HorizontalAlign="Center" SortExpression="date" />
<asp:BoundField HeaderText="Team" DataField="offense" ItemStyle-HorizontalAlign="Center" SortExpression="offense" />
<asp:BoundField HeaderText="Rush No." DataField="rush_no" ItemStyle-HorizontalAlign="Center" SortExpression="rush_no" />
<asp:BoundField HeaderText="Rush Net" DataField="rush_net" ItemStyle-HorizontalAlign="Center" SortExpression="rush_net" />
<asp:BoundField HeaderText="YPC" DataField="yards_per_carry" ItemStyle-HorizontalAlign="Center" SortExpression="yards_per_carry" />
<asp:BoundField HeaderText="Pass Att." DataField="pass_att" ItemStyle-HorizontalAlign="Center" SortExpression="pass_att" />
<asp:BoundField HeaderText="Pass Yards" DataField="pass_yards" ItemStyle-HorizontalAlign="Center" SortExpression="pass_yards" />
<asp:BoundField HeaderText="YPA" DataField="yards_per_att" ItemStyle-HorizontalAlign="Center" SortExpression="yards_per_att" />
<asp:BoundField HeaderText="No. Plays" DataField="no_plays" ItemStyle-HorizontalAlign="Center" SortExpression="no_plays" />
<asp:BoundField HeaderText="Total Yards" DataField="total_yards" ItemStyle-HorizontalAlign="Center" SortExpression="total_yards" />
<asp:BoundField HeaderText="YPP" DataField="yards_per_play" ItemStyle-HorizontalAlign="Center" SortExpression="yards_per_play" />
<asp:BoundField HeaderText="TO Margin" DataField="turnover_margin" ItemStyle-HorizontalAlign="Center" SortExpression="turnover_margin" />
<asp:BoundField HeaderText="APY" DataField="all_purpose_yards" ItemStyle-HorizontalAlign="Center" SortExpression="all_purpose_yards" />
<asp:BoundField HeaderText="Points" DataField="points" ItemStyle-HorizontalAlign="Center" SortExpression="points" />
<asp:BoundField HeaderText="Opponent" DataField="defense" ItemStyle-HorizontalAlign="Center" SortExpression="defense" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="SELECT [date], [offense], [rush_no], [rush_net], [yards_per_carry], [pass_att], [pass_yards], [yards_per_att], [no_plays], [total_yards], [yards_per_play], [turnover_margin], [all_purpose_yards], [points], [defense] FROM [cfb_boxscores] WHERE ([offense] = @offense)"
ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>">
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="offense" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
<td valign="top">
<asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>" ID="SqlDataSource3"
runat="server" SelectCommand="SELECT [date], [offense], [rush_no], [rush_net], [yards_per_carry], [pass_att], [pass_yards], [yards_per_att], [no_plays], [total_yards], [yards_per_play], [turnover_margin], [all_purpose_yards], [points], [defense] FROM [cfb_boxscores] WHERE ([date] = @date)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="date" PropertyName="SelectedValue"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
<br />
</form>
</body>
</html>
View 2 Replies
View Related
Dec 30, 2005
Hi, I've created a website usiing asp.net and all the data are stored in sql front. All the item are sorted in ascending order except one record. The correct order should be MP61, MP100, MP200, but this record is retrieved as MP100, MP200, MP61. If the coding is wrong, all the order displayed is not in ascending order. We have hundreds of items, but why it happens to this particular record? Can anyone help? Thanks in advance
View 3 Replies
View Related
Aug 16, 2002
Hi ,
Hopw can i sort the data in the ascending order so that i can see the date of my log files imported at the top of my table .
Right now my log files get imported and appended in the tables but they get appended in the descending order at the bottom of the last data .
Is there any way to sort the data so that i can see it in the reverse way when i open my tables ?
Many Thanks .
Anita.
View 1 Replies
View Related
Jan 8, 2008
Hi
I have a table with column name starts from col1 to col20. IS their anyway to insert the data and sort the table by col1 and col2 and SAVE IT.
View 3 Replies
View Related
Nov 27, 2007
Hi
I have Constructed a table
Table Name : MasterEntry
Column Name:
MasterEntryNumber
ServiceName
ServiceDepartment
EmployeeName
MasterEntryNumber is GenerationNumber where ever any entry is happen in table
if put a queries [select * From masterentry Order by MasterentryNumber] is give output in ascending order
e.g MasterEntryNumber has
1
2
3 it give correct ordering
but if i exceed more 10 if i put same queries
Output of queries is
1
10
11
2
3 this is the out of the queries if it exceed more 10 rows
i want queries should be look like this
1
2
3
...... 10
did any have experience on this issue please let me know where i can fix
kinds regards
View 8 Replies
View Related
Jul 23, 2015
I have a below table,
DECLARE @TBL TABLE (ItemId INT IDENTITY(1,1), ItemName NVARCHAR(20), ParentItemName NVARCHAR(20), ItemOrder INT, ReportId INT)
INSERT INTO @TBL (ItemName, ParentItemName, ItemOrder, ReportId)
VALUES('Item1', NULL, 1, 5),('Item1-Child1', 'Item1', 0, 5),('Item1-Child2', 'Item1', 0, 5),('Item2', NULL, 2, 5),
('Item11', NULL, 1, 6),('Item12', NULL, 2, 6),('Item12-Child1', 'Item12', 0, 6),('Item13', NULL, 3, 6)
SELECT * FROM @TBL
Here,
1. for all ReportId, child items's ItemOrder  = 0
2. example, for ReportId = 5, both child items ("Item1-Child1" & "Item1-Child1") of parent "Item1" has ItemOrder = 0
I need to,
1. update all child items with ascending numbers starts with 1 against each parent and each report.
2. for each different parent or different report, order by should starts with 1 again.
View 2 Replies
View Related
Jun 24, 2015
As bcp does not allow for the column names to be included; I have developed a method for providing the columns. The end result is that two Tables are required for each output; a "ColumnNames" table and the Table that contains the actual data; however the bcp command is sorting the data; why this is happening?Â
According to Microsoft, by default bcp will not apply any sorting unless specified.
Here is the command I am using to perform the bcp output: -
SET
@bcpCommand =(select
'bcp "SELECT * FROM GPReports.dbo.MIS001_BCPColumnNames UNIONÂ SELECT * FROM GPReports.dbo.voltemp" queryout '
+ @FilePath+'
-c -t -T')
EXEC
master..xp_cmdshell
@bcpCommand
This is the bcp topic I referred to [URL] ....
View 3 Replies
View Related
Apr 19, 2006
How to sort table in sql2000 with ipaddress(format x.x.x.x) as column with nvarchar datatype in ascending order
without using stored procedure
Ex:
Table: netComputers(3 rows)
Column Name: ipAddress (string data type)
ipAddress
0.0.18.1
0.1.1.2
0.0.0.1
Sql query : if I use the query
Select ipAddress from netComputers order by cast( replace(ipaddress,'.','') as numeric(12)) asc
Gives result as :
ipAddress
0.0.0.1
0.1.1.2
0.0.18.1
Where as expected result should be:
ipAddress
0.0.0.1
0.0.18.1
0.1.1.2
View 18 Replies
View Related
Feb 17, 2007
Hi,
i'm devoloping a web application that contains categories for example
Category1
Category11
Category111
Category1111
...........
Category112
Category12
Category2
categories with categories with categories... someone can help me about designing an elegant table for this situation.
Thanks
Fdo.
View 2 Replies
View Related
Oct 27, 2004
Hi all,
Can any body tell me how to add sub-categories to a database (MS SQL Server 2000) please.
I have a db with the following tables set:
Products: ProductID, CategoryID, ProductName…
Categories: CategoryID, CategoryName …
If a sub-category needs to be added how would I add it and what fields would it contain and the relationship between the Products and Category Table be?
Also any useful tips on this would be appreciated.
TIA
View 3 Replies
View Related
Apr 23, 2008
Hello,
I am working on a web site that makes documents available to students.
I am using tags to classify each document content.
So I have the following tables:
Documents, Tags, DocumentsTags
I also need to categorize the documents:
Subject
|---- Level
|----- Year
For example:
Document_1 - Math > University Level > Second Year
How can I create a table to create such classification?
Thank You,
Miguel
View 2 Replies
View Related
May 6, 2005
Hi,
Is there a correct way to add to the list of Categories shown in the SQL Agent Job properties dialog? I have many jobs on my servers that are [Uncategorized(Local)] as there isnt a Category title that is applicable.
Do i just insert into sysCategories?
thanks
View 2 Replies
View Related
Sep 13, 2007
Hi,
I am trying to create a type of synchronization but I am having a lot of problems to make this work.
I have 3 tables:
CREATE TABLE Articles (ArticleId INT, ArticleText NVARCHAR(512))
CREATE TABLE Categories (CategoryId INT, CategoryText NVARCHAR(512))
CREATE TABLE CategoriesInCategories (ArticleId INT, CategoryId INT)
Consider the following tables content:
Articles Table
ArticleId ArticleText
1 Game ended 1-1
2 Book Review
Categories Table
CategoryId CategoryText
1 Sports
2 Entertainment
CategoriesInArticles Table
ArticleId CategoryId
1 1
2 2
I need to create the following procedures:
CreateArticle
Create Procedure [CreateArticle]
@ArticleText NVARCHAR(512),
@ArticleCategories NVARCHAR(MAX)
As
Begin
...
End
This procedure should the the following:
1. Create the article in table Articles
2 .Use the function CSVTable that returns a table with all the categories contained in @ArticleCategories.
For each category check if there is already one with the same CategoryText in table Categories.
If there is just get the CategoryId and add a new record into CategoriesInArticles with ArticleId and found CategoryId.
If there isn't any then create the new Category into table Categories and then add the new record to CategoriesInArticles.
DeleteArticle
Create Procedure [DeleteArticle]
@ArticleId INT
As
Begin
...
End
This procedure should the the following:
1. Delete the article in tables Articles and CategoriesInArticles given its ArticleId
2 .Delete categories from table Categories that are no longer associated with any other article (in table CategoriesInArticles)
UpdateArticle
Create Procedure [UpdateArticle]
@ArticleId INT,
@ArticleText NVARCHAR(512),
@ArticleCategories NVARCHAR(MAX)
As
Begin
...
End
This procedure should the the following:
1. Update the values into Articles Table
2 .Use the function CSVTable that returns a table with all the categories contained in @ArticleCategories.
I think the easiest way is to delete all the categories from ArticleId as it is done in DeleteArticle.
Then It creates the new categories as it is done in CreateArticle.
Consider I create a new article:
EXEC CreateArticle @ArticleText = "Book launched at sports event" @ArticleCategories = "Entertainment, Business"
The tables would become:
Articles Table
ArticleId ArticleText
1 Game ended 1-1
2 Book Review
3 Book launched at sports event
Categories Table
CategoryId CategoryText
1 Sports
2 Entertainment
3 Business
CategoriesInArticles Table
ArticleId CategoryId
1 1
2 2
3 2
3 3
NOTE: Because there is no category named Business in Categories this must be created.
Then I would updated it:
EXEC UpdateArticle @ArticleId = "3" @ArticleText = "Book launched at sports event" @ArticleCategories = "Sports, Tech"
The tables would become:
Articles Table
ArticleId ArticleText
1 Game ended 1-1
2 Book Review
3 Book launched at sports event
Categories Table
CategoryId CategoryText
1 Sports
2 Entertainment
4 Tech
CategoriesInArticles Table
ArticleId CategoryId
1 1
2 2
3 1
3 4
Note: Since Business category is no longer used by any other article then it is also deleted from Categories.
The new Tech category is then created and associated with the updated article as well as the existing category Sports.
Finally I would delete it:
EXEC DeleteArticle @ArticleId = "3"
The tables would become:
Articles Table
ArticleId ArticleText
1 Game ended 1-1
2 Book Review
Categories Table
CategoryId CategoryText
1 Sports
2 Entertainment
CategoriesInArticles Table
ArticleId CategoryId
1 1
2 2
Note: Since Tech category is no longer used by any other article then it is also deleted from Categories.
The Sports category is not deleted from Categories since it is used by Article with Id=1
Well, I hope I didn't miss anything and I explained it well.
I have been trying my code, either by creating a separate procedure named SynchronizeCategories or inside the Create, Delete and Update procedure.
Until now I was not able to make this work.
Here is the code I use in my SynchronizeCategories procedure:
INSERT INTO CategoriesInArticles(CategoryId, ArticleId)
SELECT c.CategoryId, @ArticleId
FROM Categories c INNER JOIN CSVTable(@ArticleCategories) ac
ON c.CategoryText = ac.String
LEFT JOIN CategoriesInArticles cia
ON c.CategoryId= cia.CategoryId
WHERE cia.CategoryId IS NULL
INSERT INTO Categories(CategoryId, CategoryText)
SELECT cia.CategoryId, NULL
FROM CategoriesInArticles cia
JOIN [Categories] c ON c.CategoryId = cia.CategoryId
INNER JOIN CSVTable(@ArticleCategories) ac ON ac.String = c.CategoryText
WHERE c.CategoryId IS NULL
DELETE c
FROM Categories c
INNER JOIN CSVTable(@ArticleCategories) ac ON ac.String = c.CategoryText
LEFT JOIN CategoriesInArticles cia ON c.CategoryId = cia.CategoryId
WHERE cia.CategoryId IS NULL
Could someone, please, help me out with this?
Thank You Very Much,
Miguel
View 4 Replies
View Related
Oct 24, 2007
I have two tables can I print the Description from Both of them as a single Column from a select statement
Something Like
Select Trade_Category.iCategory_Name as Names,
FreeCategory.sName as Names From Trade_Category,FreeCategory Where
FreeCategory.iParent = 0 OR Trade_Category.iParent_Category = 0
But instead of two columns
Names Names
A B
A B
A B
A
Just the One
Names
A
A
A
A
B
B
B
View 2 Replies
View Related
Apr 20, 2007
Hello folks,
I've been pounding on this for a while, after countless searching I have to break down and ask for help.
I have a table set up like so:
+-----+------------+---------------+------------+
| id | title | path | category |
+-----+------------+---------------+------------+
| 1 | Firemen | firemen.pdf | CGL |
| 2 | Garages | garages.pdf | E&O |
| 3 | Auto | autos.pdf | EPLI |
| 4 | Garages | garages.pdf | CGL |
| 5 | Houses | houses.pdf | E&O |
+-----+------------+---------------+------------+
If there's a title that has more than one category (Garages for example), I would like to be able to show both categories in the same row.
Like so:
Title: Firemen
Path: firemen.pdf
Cat: CGL
Title: Garages
Path: garages.pdf
Cat: E&O, CGL
Title: Auto
Path: autos.pdf
Cat: EPLI
I assume that it might be a better set up if the category was a separate table, but I was hoping there is a way around it. I've tried grouping and subqueries but can't seem to get anything to work.
If someone could steer me in the right direction, it would greatly be appreciated. Thanks much and happy Friday!
Erik
View 2 Replies
View Related
Jun 10, 2007
hi to all;
i want to make in my site the possibility for the user to make categories in the site
ex: he can add the category name"computer science" and then can add the category childs " data mining, software engineering,... "
so firstly i want to make a category table in my databasde to be able to save the category data
haw can i make this table? i mean what are the columns that should be in the table?what type of relationship should i make? and how to mahe it
sorry but i need any one to explain to me what should i do. and if anyone one know the solution please reply to me
thanks....
View 1 Replies
View Related
Sep 27, 2007
Hi,
I would like to know how to get the Top 10 Categories from Reporting Services chart without using the scripting in T-SQL to query from db.
Is there a function like Ranking and then we filter the Ranking to be less than or equal 10 ?
Please kindly direct me in step by step to the way on how to achieve this as I am quite new in Reporting Services
Thank you
best regards,
Tanipar
View 6 Replies
View Related
Nov 24, 2007
I am creating a website that has categories such as:Sports -> Soccer -> Soccer ShoesI can not think of an effectively way to implement this into a database. Please help.
View 4 Replies
View Related
Aug 18, 2004
Ok guys,
I'm realitvely new to the whole database development stuff, but I have a very important project to finish using SQL and ASP. I am to design a new links manager for a website.
Right now I have the following:
The ability to add a link, and edit it
The ability to add a category and edit it
When you go to add a link, a list of categories is provided for you, with checkboxes. What I need to do is figure out how to assign multipule categories to one link.
I have a Cross-Referencing table with three fields:
CrossRefID
LinkID
and CatID.
If you need more clarification, post here and let me know.
Thanks in Advance,
Aaron Hawn (aaron@ionzion.net)
View 2 Replies
View Related
Oct 28, 2007
Ive got this monster which will give me a parent categoryName and the number of records linked to a child of that category, I want to use it for a directory where the list of categories has the number of records in brackets next to them. Note: a A listing will show up in each category count it is associated with
Like
Accommodation (10)
Real Estate(30)
Automotive(2)
Education(1)....
Select trade_category.iCategory_Name,Listing_category.iPa rentID,count(Listing_category.iCategoryID) as num
from Listing_category,trade_category Where Listing_category.iParentID = trade_category.iCategoryID Group by
Listing_category.iParentID,trade_category.iCategor y_Name
Union ALL
Select Freecategory.sName,Listing_category.iParentID,coun t(Listing_category.iCategoryID) as num
from Listing_category,Freecategory Where Listing_category.iParentID = Freecategory.iFreeID Group by
Listing_category.iParentID,Freecategory.sName
Which Produces
Real Estate12401 12
Extreme Sports3 4
I would Like to get the same query to produce a list of all the empty records too.
so
ID Count
Accommodation 6112 0
Real Estate 12401 12
retail 12402 0
Extreme Sports3 4
Cycling 5 0
View 2 Replies
View Related
Jun 15, 2008
I want your expert opinion to find out the best design solution to this my current issue.
1 . I have a Member Table. These members are sub categorised and again and again. So I have three three category tables which are related and all three tables directly related to the Member table via Foreign keys.
IS THIS THE CORRECT DESIGN??
2. I Have a SKILLS table where Members can select their SKILLS from that. I record this in a separate table called "MEMBER SKILLS". There is a SKILL category called "OTHER", then the Member can write those skills which may be not listed in the SKILLS table. I have created a separate column in the "MEMBER SKILLS" table it self to record this free text.
IS THIS THE CORRECT DESIGN??
3. How do you resolve a design issue where there are many nested tables of categories and sub categories and the use can create these categories dynamically as well??
I hope all above make sense to you to give a logical answer. Thank you very much for you assistance.
View 2 Replies
View Related
Jan 19, 2014
I want to get a list of any Categories where ALL the products in that Category are not published (Published = 0). (I want to get the Categories where no products are listed for it). Here are the tables, not sure where to begin :
SELECT [Id], Published
FROM Product
WHERE Published = 0
SELECT [Id] ,[Name]
FROM Category
SELECT [Id] ,[ProductId] ,[CategoryId]
FROM Product_Category_Mapping
View 3 Replies
View Related
Jun 16, 2006
I am pretty new to the DB part of this but have built an asp.net web appplication with 2 tables:
FORMS and UNITS
I have created a web page that will allow users to add forms and associate a unit with that form. I now need to be able to allow users to associate the form with multiple units.
I can change the web page list box to allow multiple selections but that doesn't solve the problem. This seems like a pretty simple task but I can't seem to find anything on it.
any help???
below is the stored procedure I was using:
CREATE PROCEDURE dbo.USP_AddForm
@UNIT_IDint,
@F_TYPE varchar(20),
@Titlevarchar(100),
@Keywords ntext = NULL,
@Descriptionntext = NULL,
@FileNamevarchar(50)
AS
BEGIN
SET NOCOUNT ON
DECLARE @NewFOrmID INT
INSERT FORMS
(
UNIT_ID,
F_TYPE,
Title,
Keywords,
Description,
FileName,
RevDate
)
VALUES
(
@UNIT_ID,
@F_TYPE,
@Title,
@Keywords,
@Description,
@FileName, GetDate()
)
SELECT @newFormID = @@IDENTITY
SELECT newFormID = @newFormID
END
GO
View 1 Replies
View Related
Aug 25, 2014
I am creating a report that will identify the website categories that our items are in. The purpose is to find items that are not in categories that they should be so they can be fixed. Attached is a csv of a subset of the data.
The data I attached has all of our Baskets by SKU (ItemNoSKU) and the associated web categories that those items are in. For example, we can see that ItemNoSKU AB107 is in web categories 4, 22, and 23.
What I have already done is get a Total Baskets vs Web Cat Baskets. I know the total baskets is 44:
Code:
SELECT MerchCatDesc, MerchSubCatDesc, COUNT(DISTINCT ItemNoSKU)
FROM myTable
GROUP BY MerchCatDesc, MerchSubCatDesc
And I know the number of baskets in WebCat 23 is 43:
Code:
SELECT WebCatCd,MerchCatDesc, MerchSubCatDesc, COUNT(DISTINCT ItemNoSKU)
FROM myTable
GROUP BY WebCatCd, MerchCatDesc, MerchSubCatDesc
So in this instance, I know there is 1 Basket ItemNoSKU that is not in WebCatCd 23. I need to list this "missing" ItemNoSKU along with the WebCatCd it is missing from. I am struggling on how to write the code to accomplish this for my full list of many categories and web categories.
View 11 Replies
View Related