Ordering Within Hierarchy
Hi all,
Ive got a bit of a problem,
I have two tables:
CATEGORY
id
name
parent_CATEGORY_id
RECORD
id
CATEGORY_id
Stock_Held_Number
ps. Ive stripped out any non relevant fields
I also have the following query (again ive stripped out the non-relevant fields)
SELECT TOP (100) PERCENT SUM(dbo.RECORD.Stock_Held_Number) AS TotalStock, CATEGORY.Name AS FundName
FROM CATEGORY
LEFT OUTER JOIN dbo.RECORD ON CATEGORY.ID = dbo.RECORD.CATEGORY_id
GROUP BY CATEGORY.Name, RECORD.Stock_Held_Number
At the moment its grouping all the CATEGORIES and giving me a sum total for each which is great.
The problem I have is the CATEGORY table, there is an optional join to parent CATEGORY records on the table.
What Im trying to do is to provide a fully ordered result within the CATEGORIES and I don't have a clue.
For example:
The CATEGORY table has the following values
ID Name Parent_Category_id
1 Pens
2 Animals
3 Rocks
4 Horses 2
5 Dogs 2
When I currently run the query I get:
Name TotalStock
Pens 20
Animals 30
Rocks 40
Horses 50
Dogs 60
It's technically correct because I don't want the parent to calculate the total value of the children
What Im really trying to do is order them within the hierarchy though and indent (if possible) the result so I would get
Name TotalStock
Animals 30
---Dogs 60
---Horses 50
Pens 20
Rocks 40
Does anybody have any pointers as to how I can achieve this.
Many thanks
Mike
View Complete Forum Thread with Replies
Related Forum Messages:
Ordering
Hi there! We are experiencing a problem using order clause in the statement below: SELECT person.pkey , first_name FROM person , private_person WHERE fkey_person = person.pkey AND first_name = 'A' ORDER BY first_name , person.pkey Where person table contains the following columns: pkey, name etc and private_person pkey, fkey_person (indexed), first_name (indexed) The output is: STEP 1 The type of query is SELECT FROM TABLE private_person Nested iteration Index : i$private_person$first_name FROM TABLE person Nested iteration Using Clustered Index pkey first_name ----------- --------------------- 2000512 A 10994 A 2299 A 1097 A 1218 A 5133 A 1329 A 1387 A 1465 A 7532 A 5513 A 1884 A 512 A 591 A (14 row(s) affected) STEP 1 The type of query is SETOFF Why SQL server does not order by pkey? Is there any information about it somewhere? Is it a bug or what? If we are ordering by fkey_person everything is Ok. Can anybody help? Thanks a lot! Kind Regards, Vladimir
View Replies !
Ordering Ids
I have a table named as C1_Messages with fields Id, Messages, Dates. My Id filed looks like this: 1000 1001 1008 1009 1084 1093 1098 etc. But here I need to make these Ids in a order, means it sould be in a consecutive order. Like 1000 1001 1002 1003 1004 1005 etc. So is there anyway to do this method in SQL? Regards Shaji
View Replies !
Hierarchy
Hello!I have a table that looks like this:Col1; Col2; Col3; Col4; Col538; 75; 233; 916; 277038; 75; 233; 916; 277138; 75; 233; 916; 277238; 75; 233; 923; 265438; 75; 233; 923; 265538; 75; 245; 913; 245438; 75; 245; 913; 2456....And I need a query (not a procedure) that shows me this:38; NULL; NULL; NULL; NULLNULL; 75; NULL; NULL; NULLNULL; NULL; 233; NULL; NULLNULL; NULL; NULL; 916; NULLNULL; NULL; NULL; NULL; 2770NULL; NULL; NULL; NULL; 2771NULL; NULL; NULL; NULL; 2772NULL; NULL; NULL; 923; NULLNULL; NULL; NULL; NULL; 2654NULL; NULL; NULL; NULL; 2655NULL; NULL; 245; NULL; NULLNULL; NULL; NULL; 913; NULLNULL; NULL; NULL; NULL; 2454NULL; NULL; NULL; NULL; 2456....Does anybody know how i can get this result? How?Help! Thank you!SQLNullps: SQL-Server 2000
View Replies !
Db Hierarchy
HI! I am new in DB so I need some advices for finding the right solution. I need to be able to make automatically any join between tables which the user choose and deliver the result. is like making an hierarchy between all tables in DB (parent-child) and then making the select statement for the right join. if u have any idea about how can I manage this, pls help me. thanks a lot!
View Replies !
Hierarchy
Hi to All! Is there a perfect method to implement a hierarchy structure with different types as a table in Sql server 2005? Currently I am thinking of this way: [Node | ParentId | ParentType | ChildId | ChildType] But there is this nagging little voice saying it can be better Cheers! Nele
View Replies !
Hierarchy
Hai everyone., i need to get solution for tree hierarchy in sql is there any solution or any keyword like 'connect by prior' in oracle .. plz help me on this.. for example: id | FName |parentid | 1 | sandy | 2 | robert| 1 if i give the parentid 1 in where condition of a query i need the details of 'sandy' Thanks in Advance. B.Arul.
View Replies !
HIERARCHY HELP! PLEASE?
I have an Interesting situation that I'm hoping some of you experts can help me with basically I have the following hierarchy: Net Profit .....Gross Profit ..........Revenue ..........Direct Costs .....Indirect Expense Now, I have another hierarchy - separate from the above - that I need to assimilate to the hierarchy above - Example: Expenses .....Node a ..........Child a (Indirect Expense Type) .....Child b (Direct Cost type) Net Sales Adjustments .....Child a (Revenue type) .....Child b (Revenue type) Depending on the type, the top most node needs to be assigned to the appropriate node in the initial hierarcy, like this: Net Profit ....Gross Profit ........Revenue ................Net Sales Adjustments ....................Child a (Revenue type) ....................Child b (Revenue type) ........Direct Costs ...........Expenses .................Child b (Direct Cost type) ........Indirect Expense ............Expenses .................Node a .....................Child a (Indirect Expense Type) Now, I've been able to figure out how to assign the top most node and leafs if all the children have the same type (using the expan stored proc listed in the books online), but my question is on this portion: Expenses .....Node a ...........Child a (Indirect Expense Type) .....Child b (Direct Cost type) Basically, the answer is to work backwards - if a child has a type that is different than the other children, a copy of the hierarch (up to the child) needs to be made and assigned to the appropriate initial node. I've tried modifying the expand stored proc to give me the lineage of the child and see if there's a way I can copy the node and place it appropriately - I'm brainfried at this point, and I'm hoping that someone outthere can point me in the right direction. Thanks in advance for your time
View Replies !
Ordering Dilemma
I have an int field - that will hold number for an ordering system. It's a databound field to a textbox in a grid, I want the default to be empty, however not all fields are required so i may have 1-6 as bound values, and the rest should fall in line behind them - the only thing i can think of to do is default the values to 9999 so they come after 1,2,3,4,5,6 etc... I don't like seeing 9999 in my bound fields. thanks for any suggestions you may have. Jeff
View Replies !
Ordering In The Table
Hello, I have made sql table called costreallocation consists of two columsn: RuleID varchar(10) Type varchar(20) I run the following three queries: insert into costreallocation(RuleId,Type)values('aa','a') insert into costreallocation(RuleId,Type)values('dd','d') insert into costreallocation(RuleId,Type)values('cc','a') then when i notice that these three records are not inserted as they are run: In the table thn there are three records : aa a cc d dd d but i need to be filled in the table as they run as: aa a dd d cc d your help is highly appreciated Best regards
View Replies !
Ordering, Grouping - HELP!
Having recently had excellent service here (many thanks, Erland!),here's another wee problem.SQL 2000I need to get a report which will display the movement of people thus:ID DIRECTION NAME DATE VEHICLE REGISTRATIONThe value of DIRECTION can be either "Inbound" or "Outbound"I need to have the data grouped by ID, with the "Outbound" row first.For example1 "Outbound" Smith 10/02/2005 ABC1231 "Inbound" Smith 11/02/2005 ABC1235 "Outbound" Jones 14/02/2005 XYZ7895 "Inbound" Jones 15/02/2005 DEF456This is the SQL so far.SELECTfldPersonID,tblMovementType.fldType AS [MovementType],'Outbound' AS [Direction],fldMovementDate AS [Date],CASE WHEN tblPerson.fldForenames IS NULLTHEN fldSurnameELSE fldSurname + ', ' + fldForenames END AS [Name],'Outbound ' + fldVehicleOut AS VehicleRegistrationFROMtblPersonINNER JOIN tblMovementTypeON tblMovementType.fldMovementTypeID = tblPerson.fldMovementTypeWHERE((fldMovementDate BETWEEN @FromDate AND @ToDate) AND(fldStatus = 1))UNION ALLSELECTfldPersonID,tblMovementType.fldType AS [MovementType],'Inbound' AS [Direction],fldMovementDate AS [Date],CASE WHEN tblPerson.fldForenames IS NULLTHEN fldSurnameELSE fldSurname + ', ' + fldForenames END AS [Name],'Inbound '+ fldVehicleRtn AS VehicleRegistrationFROMtblPersonINNER JOIN tblMovementTypeON tblMovementType.fldMovementTypeID = tblPerson.fldMovementTypeWHERE((fldMovementDate BETWEEN @FromDate AND @ToDate) AND(fldStatus = 1))What I need is the way to Order or Group it so that I can just put therows into a report without any grouping on the report itself (CrystalReports aarrggh!) - if this is possible!Edward--The reading group's reading group:http://www.bookgroup.org.ukThanks
View Replies !
Ordering Problem
Hi everyone, I have a database (not designed by me) in sql server, I amhaving trouble ordering it correctly, and I would appreciate any help.Here is my structure, it's sort of hierarchical:TABLE_AID_COLSUB_ID_COLTABLE_BID_COL'NAMEThis could be thought of as an employee and supervisor structure. Wehave employees (TABLE_B) and their relationship (TABLE_A).I know I need to use a group and oder by, but I am drawing blankstoday. I need the result to be (if using the employee example):Bob-Ryan-SueMarkNick-George-Paul--Ringo--StarHere is my half-hearted stab at it:SELECT *FROM TABLE_A AINNER JOIN TABLE_B BGROUP BY A.SUB_ID_COLORDER BY NAME;Thank you very much for any help you can offer.Have a great night!Ryan
View Replies !
Ordering An Int Column
I've created a clustered two column index on a table where the secondcolumn is an integer value. When the first column is the same, insteadof ordering in numerical order it is ordering 1,10,100,2,20,200 etc.How can I change the behaviour to order the data in numerical order?Thanks,Rick
View Replies !
ORDERING OF DATA
HOW TO ORDER THIS DATA.MONTH-YEAR10-200310-202011-20033 -20034 -20035 -20036 -20037 -20038 -20039 -2003THANX IN ADV.Join Bytes!
View Replies !
IsNull Ordering
Hi-I've got some issues with the ordering of search results. I've got 4fields, (a, b, c, d). Most often there is data in field a. Sometimesthere isn't and so then I'd like to look at field c.I can accomplish most of what I want with this:selecta as location1, ISNULL(SiteCity, SiteCityOther) AS location1,ISNULL(SiteCityOther, SiteCounty) AS location1, ISNULL(SiteCounty,SiteCountyOther)AS location1,
View Replies !
Specific Ordering
Hi, I was wondering, I have several columns of data that are able to be sorted on - the user just clicks on the column name. However, we have 1 column called order status where we don't want the order to be alphabetical (and it is a text field - a couple current possible values are Processing...In Production...Waiting For Approval). This order is not good for logical sorting - we would want to be able to specify what value would get order. Does that make sense? So we would want to be able to say that Processing is first in the display, Waiting For Approval would be next, then In Production would be next, and so on. Is there any possible way of doing this in a SQL query? Or am I going to have to manually modify all the data adding numbers to the beginning of each data so that it will sort on the numbers? Thanks everyone.
View Replies !
About Ordering Of Columns
i add new column using alter command but i always found it in the end of table but i want to add it in particular position between the columns........... how to do so .............:)
View Replies !
Ordering By Date
Hi,I'm streaming data monitoring histories of components into a database table with the following three columns: Hour (DateTime), Id (Int64), and Value (Int32). The Value entry is an aggregate of all values sent from component Id during, and 59 minutes and 59 seconds after, the time listed in the Hour column.I had rather not have to sort the queries after pulling them from the database by date. So I tried to index the DB by the Hour column. Any column will inevitably have duplicates, since the uniqueness depends on a combination of Hour and PortId. But Indexing the Hour column doesn't result in INSERTs being in order as I had expected. Instead, every entry is listed in order of insertion.So. . .how can I keep such a table ordered by date on the disk? I'm afraid this will become very inefficient if this isn't nipped in the bud right now.Thanks so much for your help!-Brandon
View Replies !
Ordering Days
I have a little query that returns me all the days in a month, but the days are not in the order I need. They come out like so.. January 10 January 11 January 12 January 13 January 14 etc January 19 January 2 January 20 January 21 January 22 here is my sample code select [month] + ' ' + [day] as [Date] from mytable where [month] = 'january' and [year] = '2004' Thanks, Jeff
View Replies !
Ordering By @parameter Possible?
Hiya! I've got a little stored procedure: CREATE PROCEDURE rICDCode @param1 char(15) = 'Description' AS SELECT DiagCode, ICD9ID, Description FROM ICDCodes ORDER BY @param1 and SQL is returning error 1008 - "The SELECT item identified by the ORDER BY number %d contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name." I want to be able to use the same stored procedure for several different functions which all need the same rowset sorted differently. Any way to do this? Thanks, Sarah
View Replies !
Custom Ordering Top 20 ?
Hi guys. I want to create a top 20 product list from a few thousand products. I want the rest of the products to be grouped into 'others'... I also want the products to be ordered by the facts in the cube. Thus the product dimension would dynamically change depending on the Time dimension thats being selected. is this plausible ? Thanks Tom
View Replies !
Advanced Ordering
Hello. I want to order a resultset from a table by two columns in another table. Here's how it looks: [Books] ID Title [linkBookAuthor] BookID (Books.ID) AuthorID (Authors.ID) [Authors] ID Firstname Lastname AuthorOrder As you can see it's a many to many relationship. Is there a way to order the books by Authors.Lastname (the first if there are several authors) with one query ? If not, what is the fastest way ? I don't need the names in the resultset so I only want to order the books by Authors.Lastname, not include Authors.Lastname. Thanks for any help.
View Replies !
Ordering By One Field Or Another
Is it possible without using CASE statements, to order a result set by one field (if the second field return value is null) or another (if the second field return value is not null) This would be on datetime fields. Let's say I have 5 records with 2 date fields sched_dt and arriv_dt. sched_dt will always have a value, arriv_dt may or may not have a value. In a single result set I would like to have the records with an arriv_dt sorted by arriv_dt and the ones without an arriv_dt sorted by sched_dt. *Hope that makes sense* Thanks
View Replies !
Ordering Dates
I have a table that has 4 dates for each record (birthday, anniversary, policy_start & policy_end). What I want to do is cycle through each record and then do some calculations using the gaps between the dates. So it might be Calc1 using (birthday->anniversary), Calc2(anniverary->policy_start), Calc3(policy_start->policy_end), etc. BUT the dates might be in different orders (ie the birthday could come first - or the anniverary could, etc). In VBA in Excel, I can use the SMALL function within my calcs and this returns the minimum date, the next smallest, the next & then the biggest. But how can I do this in SQL. I guess I can push the 4 dates out to a temp table, order it and then suck them back in - but I have no idea how to do this for all the records in my primary table I've also tried using various WHERE statements (ie do Calc1 using Birthday & Anniversary WHERE Birthday < Anniversary and ........ - but the code gets awfully long. Is it possible to write my own SMALL function which uses a bubble sort on the 4 dates & then returns the smallest, next smallest, etc Any thoughts ?
View Replies !
Ordering Table
hello everybody, I've got a question concerning a sql statement on a table. I have a table that displays several countries. Now I would like to sort these countries. Country Netherlands Germany England Austria This colom must be ordered beginning by Netherlands. By using the default order by i can't fix this so is there another way?
View Replies !
Re-ordering Records
Hi all, Ive got a table with a field called 'morder' which orders a menu based on the values in this field (1 for position 1, 2 for position 2 etc...) for example 1 - menu item 1 2 - menu item 2 3 - menu item 3 4 - menu item 4 If I want to add a record to this table and put it at number 2 in the list, i need to update the table to then read... 1 - menu item 1 2 - NEW menu item 2 3 - menu item 2 4 - menu item 3 5 - menu item 4 I want to use a mssql or php function to re-order this field... is it possible?? Hope you can help, and hope it makes sense... Ash
View Replies !
For Each File - Ordering?
Does anyone know in what order files are processed if using a for each container and file enumerator? Does it sort files alphabetically and loop through? Or use a date time stamp? Or something else? I need files to be processed in a certain order, and the ordering is in the filename, so the foreach file enumerator sorts on filename, then I'm ok, otherwise I need to figure something else out. Thanks.
View Replies !
Ordering Date ?
SELECT LEFT(CONVERT(CHAR(11),convert(datetime,task_date),109),3) + ' ' + RIGHT(CONVERT(CHAR(11),convert(datetime,task_date),109),4) as Date, SUM(CASE a.status_id WHEN 1000 THEN b.act_point ELSE 0 END) as Programming, SUM(CASE a.status_id WHEN 1016 THEN b.act_point ELSE 0 END) as Design, SUM(CASE a.status_id WHEN 1752 THEN b.act_point ELSE 0 END) as Upload, SUM(CASE a.status_id WHEN 1032 THEN b.act_point ELSE 0 END) as Testing, SUM(CASE a.status_id WHEN 1128 THEN b.act_point ELSE 0 END) as Meeting, SUM(CASE a.status_id WHEN 1172 THEN b.act_point ELSE 0 END) as Others From task_table a,act_table b where a.status_id=b.act_id and a.user_id=(select user_id from user_table where user_name='Raghu') and a.task_date like '%/%/2006' GROUP BY LEFT(CONVERT(CHAR(11),convert(datetime,task_date),109),3) + ' ' + RIGHT(CONVERT(CHAR(11),convert(datetime,task_date),109),4) Output : Aug 2006 294 0 0 80 0 0 Jan 2006 14 0 0 0 0 0 Oct 2006 336 0 0 0 0 0 Sep 2006 3262 20 24 8 16 0 How to sort the date in ascending Order ? Jan 2006 Aug 2006 Sep 2006 Oct 2006
View Replies !
Union Ordering
Hello, I'm attempting to run three separate queries and have them returned as one recordset. I need to show the top 10 customers based on the number of orders they placed for each of three months, then combine them to give a representation of which customers have been within the monthly top 10 for the overall period of three months. My problem is when I run a count on the number of orders they have placed and order by that count, it is in ascending order which in escence shows me the bottom 10, not the top 10. To resolve this issue, I can specify descending order. This works fine with one query, but when I run all three queries using union statements, I can only have one order by which returns incorrect results. Here is my query. In this example, I get the combination of the three recordsets as expected, but each of the individual queries is not ordering descending, so I get the wrong end of the table. I am not bound to union, but do not know where to go. I do not believe I can use joins or concatenate queries because I have multiple where clauses. Any help would be greatly appreciated. Please note that I am using a view to convert the cryptic field names which are used by a third party software tool into more friendly names. We will call this view Friendly_View for this example. USE MyDB SELECT TOP 10 CustName, Location, Phone, COUNT(Orders) AS TotalOrders FROM Friendly_View WHERE MONTH([Order Date]) = MONTH(GETDATE())-1 AND YEAR([Order Date]) = YEAR(GETDATE()) GROUP BY CustName, Location, Phone UNION SELECT TOP 10 CustName, Location, Phone, COUNT(Orders) AS TotalOrders FROM Friendly_View WHERE MONTH([Order Date]) = MONTH(GETDATE())-2 AND YEAR([Order Date]) = YEAR(GETDATE()) GROUP BY CustName, Location, Phone UNION SELECT TOP 10 CustName, Location, Phone, COUNT(Orders) AS TotalOrders FROM Friendly_View WHERE MONTH([Order Date]) = MONTH(GETDATE())-3 AND YEAR([Order Date]) = YEAR(GETDATE()) GROUP BY CustName, Location, Phone ORDER BY COUNT(Orders) DESC
View Replies !
Message Ordering
When I am receiving a batch of message from a queue to process, does it matter if I order by the queuing_order or the message_sequence_number? I want to make sure my messages process in the order in which they were put into the queue, which I know will happen if I process messages one-by-one, but want to make sure that the data I pull and process execute in the order in which they were received. Tim
View Replies !
Ordering Rows
hi, i have following data: create table tb_customer (customer_id int, order_id varchar (12)) insert into tb_customer (customer_id, order_id) values (123, 2201) insert into tb_customer (customer_id, order_id) values (123, 2246) insert into tb_customer (customer_id, order_id) values (123, 2236) insert into tb_customer (customer_id, order_id) values (123, 1253) insert into tb_customer (customer_id, order_id) values (120, 1201) insert into tb_customer (customer_id, order_id) values (127, 2251) insert into tb_customer (customer_id, order_id) values (127, 2231) insert into tb_customer (customer_id, order_id) values (122, 2121) and i want to get the following output: output: Nu_order | customer_id| order_id 1 |123| 2201 2 |123| 2246 3 |123| 2236 4 |123| 1253 1 |120| 1201 1 |127| 2251 2 |127| 2231 1 |122| 2121 any idea? thank you
View Replies !
Ordering Results
I am trying to do a simple SQL query..the result will be sorted alphabetically by default, but i need to specify say, if there is a "Others" it will be placed last in the list. Is there any way to write the query using ORDER BY? e.g Australia China Others USA and i want it to be: Australia CHina USA OThers
View Replies !
Ordering By Months
I am wondering if someone maybe able to help me, I am needing to order my data via months in the calendar sense not alphabetically, below is what I currently have, but it only does it alphabetically. select to_char(created,'yyyy-Mon'), matdesc, count(*) from test group by to_char(created,'yyyy-Mon'), matdesc order by to_char(created,'yyyy-Mon') desc any help would be greatly appreciated Thank you Stephen
View Replies !
One Attribute Having Different Ordering In Two Hie
Hello All, I have a Day attribute in my Time Dimensions. This attribute is used in two different hierarchies ( Calendar Year Hierarchy and Fiscal Year Hierarchy). I want Day attribute to have ascending order in Calendar Year Hierarchy and descending order in Fiscal Year Hierarchy. Since the OrderBy property is at the attribute level is there any way I can achieve this by not having a redundant Day attribute? Please advice. Regards Jasraja
View Replies !
Hierarchy And SQL 2000 Help
Hi there, I am rather new to programming and am looking for some help / an example of how i can get a hierarchical / netsted view of data from a simple database in SQL2000. (I am using asp.net express edition). The schema has 4 tables; Table1 linked to Table2, Table2 to Table3, Table3 to Table4. (All tables have a relationship to themselfs in a parent child format.) I would like to display the data in a hierarchical or netsted type of gridview. is this enought detail... i could not find how to post a picture of the schema or desired output... so i hope so... Any help would be great... many thanks! Tod
View Replies !
Hierarchy ORBER BY
Hi, I'm trying to figure out how to write I SP on the following table that will produce the results show at the bottom. My main problem is the sorting, is there a way I loop through the records in TSQL and ORDER BY SortSort where the ParentID's are the same? Thank you. Table example IDParentIDSortOrderCaption 1null1Main 211Files 313Folders 422File2 512Holders 621File1 752Holder2 851Holder1 Required result example Main -Files --File1 --File2 -Holders --Holder1 --Holder2 -Folders
View Replies !
Update Hierarchy
I have structure:FolderId, FolderName, ParentFolderId, FullPathe.g.1, First, null, First2, Sec, 1, First/Sec.....When update happens to FolderName, i need to update all FullPaths thatare below Folder which is changing.Any ideas?Thank you.
View Replies !
Sparse Hierarchy T-SQL Help...PLEASE?
Greetings!I could really use some suggestions on how to improve on thefollowing, it at all possible:Table 'Customer'---------------------ID GUID PK....Table 'Facility'-----------------ID GUID PKCustomerID GUID FK (FK to Customer GUID)....Table 'Rate'----------------ID PKOwnerID GUID Nullable FK (FK to Customer, Facility GUID PK)OwnerLevel INT Contraint 1-3<Rate Data>Table 'Rate' is a sparse hierarchy of data. There are 3 possiblelevels in the hierarchy as follows:OwnerID <NULL>OwnerLevel 1This indicates Global rate data.OwnerID <Customer.ID>OwnerLevel 2This indicates Customer-specific rate data.OwnerID <Facility.ID>OwnerLevel 3This indicates Facility-specific rate data.Now, a given Customer need not have an entry in the Rate table. If aCustomer does not have an entry, it is supposed to 'inherit' Globalrate data. A given Facility need not have an entry in the Rate table.If a Facility does not have an entry, it is supposed to inheritCustomer-specific rate data, and in the absence of an entry for theFacility's parent Customer, it is supposed to inherit Global ratedata.The challenge is that I want to write a view to give me back theappropriate rate record for Customer and Facility. Here's what I'vedone so far.View _Rate--------------SELECTRate.*,NULL AS TargetIDFROMRateWHERERate.OwnerID IS NULLUNIONSELECTRate.*,Customer.ID AS TargetIDFROMRateCROSS JOINCustomerWHERERate.OwnerID IS NULLOR Rate.OwnerID = Customer.IDUNIONSELECTRate.*,Facility.ID AS TargetIDFROMRateCROSS JOINFacilityWHERERate.OwnerID IS NULLOR Rate.OwnerID IN (Facility.CustomerID, Facility.ID)View view_Rate--------------------SELECT_Rate.*FROM_RateINNER JOIN(SELECTTargetID,MAX(OwnerLevel) AS OwnerLevelFROM_RateGROUP BYTargetID) AS Filtered_RateON_Rate.TargetID = Filtered_Rate.TargetIDAND _Rate.OwnerLevel = Filtered_Rate.OwnerLevelThe combination of these two views gives a resultset that contains 1record for every Target ID as follows:TargetID <NULL>OwnerID <NULL>OwnerLevel 1This indicates Global rate data established at the Global level.TargetID <Customer.ID>OwnerID <NULL>OwnerLevel 1This indicates Customer rate data for the specific Customer identifiedby Customer.ID is inherited from the Global rate data.TargetID <Customer.ID>OwnerID <Customer.ID>OwnerLevel 2This indicates Customer-specific rate data for the specific Customeridentified by Customer.ID (not inherited).TargetID <Facility.ID>OwnerID <NULL>OwnerLevel 3This indicates Facility rate data is inherited from the Global ratedata.TargetID <Facility.ID>OwnerID <Customer.ID>OwnerLevel 2This indicates Facility rate data for the specific Facility identifiedby Facility.ID is inherited from the Facility's parent Customer'sCustomer-specific rate data.TargetID <Facility.ID>OwnerID <Facility.ID>OwnerLevel 3This indicates Facility-specific rate data for the specific Facilityidentified by Facility.ID (not inherited).I know this is a lengthy post, and a complicted query scenario, butI'm not willing to accept that my solution is the best solution justyet. Please consider that I really need this functionality in a VIEWas much as possible.Thank you for your learned consideration.I eagerly await your replies.Darryll
View Replies !
Treeview Hierarchy With SQL And XML! Help!
I am trying to create a treeview structure with SQL and XML. This type of structure uses the typical Root->Folder->Item(Folder...Item) Windows Explorer type of Parent/child relationship. I am currently trying to use FOR XML EXPLICIT which requires you to define the shape of the XML document ahead of time. However, this type of structure is dynamic; you won't always know how many levels deep of nesting there will be. Has anyone done this with SQL and For Explicit. Does anyone have any tips? Thanks in advance for you help! Kurt
View Replies !
Dynamic Hierarchy
Hi people In have a query over two tables, and the ouptut is: RowID | SubMarcaID | MarcaID | ProductoID 1 | 1 | 1 | 1 2 | 1 | 1 | 2 3 | 1 | 1 | NULL 4 | 3 | 1 | 3 5 | 3 | 1 | NULL (SubMarcaID and MarcaID are the KEYS from SUBMARCA, and ProductoID is the key from PRODUCTO. Also SubMarcaID and MarcaID are foreing keys on PRODUCTO) Now, I need a ParentRowID based on SubMarcaID and MarcaID, like a hierarchy RowID | SubMarcaID | MarcaID | ProductoID | ParentRowID 1 | 1 | 1 | 1 | 3 2 | 1 | 1 | 2 | 3 3 | 1 | 1 | NULL | 0 4 | 3 | 1 | 3 | 5 5 | 3 | 1 | NULL | 0 How can I do this? Code Block SELECT ROW_NUMBER() OVER (ORDER BY PRODUCTO.MarcaID, PRODUCTO.SubMarcaID) AS RowID, PRODUCTO.SubMarcaID, PRODUCTO.MarcaID, PRODUCTO.ProductoID FROM PRODUCTO, SGP_SUBMARCA WHERE PRODUCTO.SubMarcaID = SUBMARCA.SubMarcaID AND PRODUCTO.MarcaID = SUBMARCA.MarcaID GROUP BY PRODUCTO.SubMarcaID, PRODUCTO.MarcaID, PRODUCTO.ProductoID WITH ROLLUP HAVING ( GROUPING(PRODUCTO.ProductoID) = 1 AND GROUPING(PRODUCTO.SubMarcaID) = 0 AND GROUPING(PRODUCTO.MarcaID) = 0 ) OR ( GROUPING(PRODUCTO.SubMarcaID) = 0 AND GROUPING(PRODUCTO.MarcaID) = 0 AND GROUPING(PRODUCTO.ProductoID) = 0 )
View Replies !
Use Hierarchy From SSAS
Hello experts, Last time I worked with SSAS and build a Cube. Because I€™m now very happy with the front-end excel 2003 or excel 2007 I thought I build my own Report with SSRS. Now there is something I don€™t understand: I build a Hierarchy in SSAS that a want to use in SSRS. Is there a chance to use it without any features? Have I to use parameters or something another? In my opinion it makes any sense to build a hierarchy new, because it€™s already exists in SSAS. Have a nice day Alex
View Replies !
Graph Hierarchy: What Is It Exactly?!!
Hi everybody, I've been reading the book MCITP Self-Paced Training Kit (Exam 70-441): Designing Database Solutions by Using Microsoft SQL Server(TM) 2005 (Self-Paced Training Kits) as a part of my preparation for exam 70-441 The book is really clear, and I could understand everything easily because I've some experience as a database developer. Until now, there's only one thing that I didn't fully understand: On pages 53 and 54, it mentions a type of hierarchy called: a graph hierarchy, and it gives a small example made the things even more complicated I've many books about database design theories, but they don't use the term (graph hierarchy) any where... So, I appreciate if you can point me to an online resource or a book that discusses this term thorougly. Thank you
View Replies !
How To Get The Data In A Hierarchy?
How can I get the data from a table that stores hierarchical information keeping the right order and hierarchy levels? I also need to specify a first level....let me explain. Table: Sites Id (PK) Title Url ParentId If I have something like this: 1 | Test | http://localhost | NULL 2 | Sub-Test | http://localhost/subtest | 1 3 | SecondItem | http://anotherServer | NULL 4 | ChildOfSub-Test | http://localhost/subtest/child | 2 And I specify that I want all child items below the Id 2, it must return: Id | Title | Url | ParentId | Depth 2 | Sub-Test | http://localhost/subtest | 1 | 0 4 | ChildOfSub-Test | http://localhost/subtest/child | 2 | 1 How can I do this? I've saw some examples with CTEs, but they always return all of the items.
View Replies !
Hierarchy In Sql Server
Hello , I'm facing a complicated problem and I don't think that the solution will be an easy one. I have an SQL statement in Oracle which I need to translate it in Sql Server 2005. select lpad(' ',5*(orderid)) || to_char(descr) as menui from <table _name> where MENU_ITEM not in ('test1','test2','test3') and item_parent not in ('test4,'test5,'test6') start with <item_parent='item_parent' > connect by prior <menu_item = item_parent and menu_name='something'; > ?(condition) Somewhere I have read that SQL server does not support Hierarchical Sql statements. Is this true ? How am I going to do that ? Any help will be appreciated. Thank you
View Replies !
Hierarchy Level
Hi i tried on CTE but iam not gettng correct result plz help me Declare @TMaster Table (MasterId int, Type varchar(100), ParentMasterId int) Insert into @Tmaster Select 1, 'Fixed', 14 Union All Select 2, 'Flexible',14 union All Select 3, 'Others',14 union All Select 13, 'Retirement benefits',1 union All Select 14, 'PBHeads', 0 Select * From @Tmaster Declare @TDetails Table ( MasterId Int, Description varchar(100)) Insert into @TDetails Select 1, 'Basic' union all Select 1,'Conveyance' union all Select 1,'HRA' union all Select 1,'Special Allowance' union all Select 2, 'Children Education' union all Select 2,'Travel Allowance' union all Select 2,'Medical Expenses' union all Select 2,'Variable Spl Pay' union all Select 3, 'Project Allowance' union all Select 3,'Quarterly Incentive' union all Select 3,'Shift Allowance' union all Select 3,'Annual Component' union all Select 13,'Provident Fund' union all Select 13,'Gratuity' union all Select 13,'Super annuation' Select * From @TDetails in group list we have to show fixed, flexible, other in subgroups(L1) list under fixed we have to show Basic salary, HRA, Conveyance, Special Allowance,Retirement benefits in subgroup(L2) we have to show Gratuity, providedfund, Super annuation they are subgroups of retirementbenefits output : Group Subgroup(L1) Subgroup(L2) Fixed Basic salary HRA Conveyance Special Allowance Retirement benefits Provident Fund Gratuity Super annuation Flexible reimbursements LTA/Group Travel Medical expenses Children education variable special pay Others Project allowance Performance incentive Medical insurance
View Replies !
Parameter Hierarchy
how do i create a parameter in hierarchy? SAMPLE billing period: YEAR 2007 1st quarter jan feb mar 2nd quarter april may june something like that.... if the user chose the 1st quarter the report will generate a sum-up report for the 1st quarter of 2007... kindly reply asap.. i really need to get this report working.. thanks!
View Replies !
|