Adjacency List From SQL Table To XML File

Nov 19, 2007

I'm having trouble generating an XML file from a sql table. Basically its an HR Dept. table that has departmentID and ParentDepartmentID. I need to create a hierarchal xml file that has a parent node, and all its departments, and if any of the sub departments have any below them, stick those departments in accordingly. I can do this two ways...either through tSQL or through .NET recursive methods. I've tried the recursion but can't wrap my head around it enough to get it working.

Here is the table schema:




Code BlockCREATE TABLE [dbo].[DepartmentTree](
[DepartmentID] [varchar](13) NOT NULL,
[ParentDepartmentID] [varchar](13) NOT NULL,
[Description] [varchar](30) NOT NULL,
[ManagerEmployeeID] [varchar](13) NOT NULL
) ON [PRIMARY]





here is the xml markup I'm looking for (or facsimile thereof...doesnt really matter)




Code Block
<?xml version="1.0" encoding="UTF-8" ?>
<Department ID="1" Name="IT" Manager="12345">

<Department ID="2" Name="IT Info. Sys" Manager="23456" />
<Department ID="3" Name="IT Technical" Manager="34567">

<Department ID="4" Name="IT Technical West" Manager="45678" />
<Department ID="5" Name="IT Technical East" Manager="56789" />
</Department>
</Department>




Here is my test data:





DepartmentID
ParentDepartmentID
Description
ManagerEmployeeID

1
1
IT
12345

2
1
IT Info. Sys
23456

3
1
IT Technical
34567

4
3
IT Technical West
45678

5
3
IT Technical East
56789



Does anyone have a suggestion as to how to do this?

View 5 Replies


ADVERTISEMENT

SQL Server 2008 :: Converting Adjacency List To Hierarchy Table

Feb 10, 2015

I have been trying to convert an existing table that used adjacency list model (parentid,childid) to a table that use hierarchy Id type. So early on, I notice my original data does contains multiple roots. So I took a step to create dummy nodes to ensure all nodes fall into a single root structure. Another important fact is that each child node can have multiple parents.

My original source table contains 22461 records, when running the query below step 2 produces explosive number of records around 175,000+ records. I spent hours study the result and couldn't understand what actually causing this, I ran it against small set of test data I didn't seem the issue caused by child with multiple parents.

select * from SourceTable -- produces 22461 records

--step 1: first, get row number of child records in each parent

SELECT ChildID,ParentID, ROW_NUMBER() OVER (PARTITION BY PARENTID ORDER BY PARENTID) as Num
INTO #RelationshipTmp
FROM SourceTable;

[Code] ....

View 1 Replies View Related

Adjacency Matrix In MDS With A Recursive Derived Hierarchy?

Apr 30, 2014

If you've ever worked with CI (UPC barcodes), certain commercially distributed products can be "packaged" in certain ways as defined by suppliers. For example, buying a six-pack of Coca-Cola, each one of the cans have a barcode UPC that indicates that the particular can is to only be distributed as part of a "pack" - they can't be distributed or sold individually.

Certain products can be distributed and sold in more than one way. For example, that same six pack can be distributed and sold as a case bundle, or it can be distributed as a single six pack. Each packaging method has a certain hierarchy.you can't represent the CI model using anything less than an adjacency matrix.Now, this can be represented in SQL pretty easily - there's tons of examples online that go through the basics of how to do it and how to write the recursive CTE function to represent and return data in this format. My problem is with MDS.

In Master Data Services (MDS) you have several hierarchy types to choose from. The hierarchy type that makes the most sense to me is to use the recursive derived hierarchy. It makes sense because I want to define an entity that contains all the "acceptable" adjacencies for particular items, such that when a user looks at the data in MDS or tries to update its value, it will have certain domain-based enforcement (and thusly lookups).I think that I've crossed a bridge too far with MDS - but, perhaps one of you knows something I don't know. It looks like any hierarchy in MDS is only based in a parent - child relationship, so that's not quite what the doctor ordered here.

View 0 Replies View Related

SSIS Loading DWH Staging Area When Table Names Is Selected From Table List

Aug 31, 2007

Hello,
Maybe anyone have done that before?
I have table where i store SOURCE_TABLE_NAME and DESTINATION_TABLE_NAME, there is about 120+ tables.
i need make SSIS package which selects SOURCE_TABLE_NAME from source ole db, and loads it to DESTINATION_TABLE_NAME in destination ole db.

I made such SSIS package. set ole db source data access mode to table or view name variable.
set ole db destination data access mode to table or view name variable. set to variables defoult values (names of existing tables)
but when i loop table names is changed, it reports error, that can map columns, becouse in new tables is different columns.

how to solve that problem?

View 5 Replies View Related

How To List All File Groups

Jul 20, 2004

How to list all the file groups

View 1 Replies View Related

Multiple Table Query - How To Get List Of All Values For Each Table

Jun 7, 2012

I have a database that has 370 tables that match %_REF_% naming. All of these tables have a column call ds_name.

I need to get a list of all values of ds_name for each table.

View 3 Replies View Related

Get File List In Specified Folder Through Sqlserver

Mar 20, 2008

Problem:
like in .net or any other language,we can get the file list in a specified folder
How we can do this through sqlserver (stored procedure or any thing else)
I want to show the file name list(by providing the path of any folder on system) in sql query analyser by running any script for that
Thanks........ 
 
 
 
 

View 1 Replies View Related

IS There A Way To Store List Of Errors In Text File

Apr 4, 2007

I want to attach a error list to my email task and i want my email task to send email only if there is an error...IS this possible..

View 8 Replies View Related

Transact SQL :: List All File-groups For All Databases?

May 27, 2009

I would like to SELECT all filegroup on an SQL server instance, is that possible?Or only per database?

View 21 Replies View Related

How Do I List Contents Of File Directory In The SQL Query Analyzer

Apr 13, 2006

how do I list contents of file directory in the SQL Query Analyzer

View 1 Replies View Related

SQL Server 2012 :: Query From A List In Excel File

Feb 11, 2014

I have database tables for

Stores
StoreId, Name

Products
ProductId, Name

Transactions
TransactionId, StoreId, ProductId

I was just given an excel file with a list of 300 Stores.

I need to find out if these stores are selling our products and if they are , how many products they are selling.

One way of doing this , that I can think of right now is individually querying the Transactions table for each of the store in the excel sheet and then copy the results output back to the excel sheet.

Is there a way I can write a query against all the Store names from the excel file ? I need to get this done in the next few hours.

View 9 Replies View Related

To List Ssis Packages Stored In File Folder

Nov 13, 2007

Hi,
newbie to sql2005. I am trying to write a VB.NET program to list all ssis packages we have stored in a file folder (not in MSDB) where both SqlServer and ssis servers are located. These packages currently running on daily basis by automated jobs with no problem.

I have found the following link on the web that includes VB.Net program. If you scroll down under Example (SSIS Package Store) , you'll see a VB.NET program that I am trying to get it to work for me but keep getting error message like "Cannot find folder......"

http://msdn2.microsoft.com/en-us/library/ms403343.aspx



My goal is to:
1. List all ssis packages stored in the file systems (.dstx)
2. List DB source and distination providers(tables in/out) in a ssis package
3. List properties for DB providers
4. List FlatFile & Excel file provider properties in a ssis package.
My assumption, but not sure, is that I may need to register this file folder (where packages are located) to the SqlServer if that is not done already. Any command or sys table in Sql2005 to figure this out?

I would appreciate any help on this in advance.
Thank You.

View 4 Replies View Related

ForEach File In Folder - Missing From Dropdown List

Jun 28, 2007

I'm working through the SSIS tutorial, and am on lesson 2.
This says
"Double-click Foreach File in Folder to reopen the Foreach Loop Editor.

Click Collection.

On the Collection page, select Foreach File Enumerator."

The drop down only contains

foreach ado enumerator
foreach ado.net schema_rowset.enumerator
foreach from variable.enumerator
foreach nodelist.enumerator
foreach smo.enumerator


How do I get the "foreach file in folder" to appear in the drop down list?

Gary

View 3 Replies View Related

SQL Server 2012 :: Query Servers From A List For File Storage Information

Oct 13, 2014

I have a group of about 5 servers (which will likely grow toabout 25 in the near future) with their names listed in a table in a database on one of the servers. I want to query all servers in that table using the following query to pull the storage drive, database name, created date, age and size of the databases for each server listed in the table:

SELECT left(mf.Physical_Name,2) AS Storage_Drive,
DB_NAME(mf.database_id) AS DatabaseName,
db.create_Date,
DateDiff(day, db.create_date, getDate()) Age,
sum((mf.size*8))/1024 SizeMB

[Code] ...

How would I best accomplish this if I want to implement it using a TSQL procedure?

View 4 Replies View Related

Flat File Connection Manager Is Miising In Data Source List

Jul 30, 2007

I want to use Import/Export wizard. In "Choose a data Source" screen, I can't see "Flat File" in "Data Source" List. Please help me how to insatall (or find) flat file connection manager

Thanks

View 2 Replies View Related

Please Help Me About List Of Table

Dec 14, 2005

i need to give list all table in my database plaese give me qurity?
thanks a lot

View 4 Replies View Related

Getting A Table List

Feb 24, 2004

Hello,


If you need to have a liste of tables starting with 'WI', under Oracle for example, with a simple select of a system view (with a filter : table_name like 'WI%') you have the result.
Under SQL Server, how to do this simply (sp_tables ?) ?

Thanks in advance

View 14 Replies View Related

How To Get Table List From A Db? Thanks!

Aug 2, 2005

Hi Group!I would like to get a list of all the table names from a database, cananybody please tell me how to do that? Many thanks!

View 4 Replies View Related

Integration Services :: Updating List Of Tables From CSV File Based On Values In Columns

Jun 16, 2015

Here is a requirement. Need to update the columns in the tables with the latest values available in CSV.

The file is based on department so the list of tables which is under this department all the corresponding tables needs to updated.

The CSV file which is dynamic in nature the number of columns changes it has header of the columns that needs to be updated.

The destination tables are listed under department table for each department. So I have to update the columns in the tables with the values in csv.

View 4 Replies View Related

Getting The List Of Column In A Table

Dec 3, 2002

Hi,
i want to get the list of column i have in a table using sql statment
can someone send me example?

thanks

View 7 Replies View Related

List Table Name And Size

Jul 29, 2002

Anybody know any method/script I can use to see a list of table name
and table size (in bytes, not rows) within a database?
I know I can see the size of any particular table in "Table info" tab or using "sp_spaceused" procedure. But I can't generate a report with a list of table name and table size using these methods.
Any idea? Thanks.

John

View 2 Replies View Related

How To Get A TOP10 List From A Table?

Dec 17, 2007

SELECT Item.Unit_price
FROM Item
ORDER BY Item.Unit_price DESC

How can I display the Top10 only? thanks.

View 2 Replies View Related

Comparing List To A Table

Mar 18, 2008

Hi guys, i'm sort of stuck.

I have a list of names, all i have to do is check to see if any of them are in a table, if they are they get deleted. The unique field of the table is title and it is what i have. I don't really know how i am meant to do this. I thought of creating a new table, placing my values into it and comparing to the already existing table, but surely their is a simple way?

View 3 Replies View Related

Database Table List

Sep 10, 2007

Is there a system table that holds the table definitions, names, properties, etc. for tables that I have designed? I would like to write a transact SQL query to insert a field in every table that I have defined.

View 1 Replies View Related

List Of Table In A Database

Apr 1, 2006

Please how can I get list of tables in a database? Thanks.

View 3 Replies View Related

List Of Modified Table ?

Jan 7, 2008

Hi Everybody,

i am it sutck when i am writing this sql in sqlserver2005

my requirement is to list all the table name and along with their filed name if some one modified (table definition ) for a specifc date range ?

is there any way to get these information in sql server 2005 ?



regards

sujithf

View 3 Replies View Related

List Of All Relations Of Database's Table.

Dec 16, 2006

Hi,How to get list of all relations of certein database's table?

View 7 Replies View Related

Radiobutton List From SQL Server Table

Mar 29, 2007

Hi! There must be a very simple answer to this question, but it’s my first venture into using SQL Server data.
 
I’ve set up an ASP.NET site to provide for on-line sign-up of events.  The site has a masterpage and utilizes a wizard to create an e-mail to request sign-up for an event. 
 
I’d like to make my radiobuttonlist dynamic so that events past the signup deadline will not be displayed.  So, I’ve created a database table that includes two fields: event_description and event_date – such that the radiobuttonlist will only show those events that are at least three days beyond today’s date.
 
I’ve configured the data source and the radiobuttonlist so that I can display all the entries in the event table, but I can’t figure out how to restrict them to today + 3 events only.
 
I’m guessing my problem is in the “Add Where Clauseâ€? of the “Configure Data Sourceâ€? wizard.  I’m sure the “Columnâ€? should be set to event_date and the “Operatorâ€? should be set to “>â€?, but what should I set the “Sourceâ€? & “Parameter Propertiesâ€? to?  I’ve set a variable in my program as “Dim deadline As Date = Today.AddDays(3)â€?, but the wizard doesn’t seem to see it.
 
Can anyone steer me in the right direction?
 Thanks, Jerry

View 3 Replies View Related

Dropdown List And Data From A Table

Feb 2, 2004

Hi masters

well got a SQL server 7 and a table

and got drop down list in my asp page

what I want to do is that the content and value of the drop down list will be grabbed from the database, when page loads.

can you please guide me

many thanks

S

View 1 Replies View Related

How To Populate Table From Dropdown List?

Oct 18, 2005

Hi,I have table (tbl_a) that get it values form three Dropdown List and the PK of this table is FK in different table(tbl_b).Since tbl_a get its values from three Dropdown List the number of rows in this table is limited to the number of combinations the three Dropdown List is offer (in any case the number of raws in that table will be final).Assuming tbl_a and tbl_b are both empty.
The problem is that if i want to insert row to tbl_b i have to check first if there is a row that holds the values (or combination of values) i am getting from the Dropdown List in tbl_a .Then, if such row is exist i have to get the PK of that raw and insert it to tbl_b (as FK),if such row does not exist, i have to insert it and then get the PK of this row and insert it to tbl_b (as FK).
In the end, tbl_a will have all the combination the three Dropdown List can offer so checking if raw exist in this table will not be necessary.
In my opinion this is not effective way to do that.Can someone offer me better way to do it?
Thanks

View 6 Replies View Related

List Of All Table Sizes In A Databases

Mar 6, 2000

Hi,

Is there a query I can run to retrieve a list of all tables and their sizes in a database? I want something that is like the feature in Enterprise Manager when you click on a database and then the 'Tables & Index' link. It lists the tables and their respective size. I want to push this into a spread sheet.

The reason why I am doing this is the compare data between 2 different databases. Since I cannot find a tool that will compare the data, the closest I can get (without bcp-ing out all data and comparing) is to look at the sizes of each table.

Thanks!
Joyce

View 2 Replies View Related

Getting Database Specific Table List From ADO

Aug 21, 2000

We are listing available SQL databases for selection in a VB list box, but need to be able to then elicit the tables in the database for another list. I am sure it is something simple, could someone help me out with this? Thanks!!
Laura

View 1 Replies View Related

How To Populate Table From Dropdown List?

Oct 18, 2005

Hi,
I have table (tbl_a) that get it values form three Dropdown List and the PK of this table is FK in different table(tbl_b).
Since tbl_a get its values from three Dropdown List the number of rows in this table
is limited to the number of combinations the three Dropdown List is offer (in any case the number of raws in that table will be final).
Assuming tbl_a and tbl_b are both empty.

The problem is that if i want to insert row to tbl_b i have to check first if there is a row that holds the
values (or combination of values) i am getting from the Dropdown List in tbl_a .
Then, if such row is exist i have to get the PK of that raw and insert it to tbl_b (as FK),
if such row does not exist, i have to insert it and then get the PK of this row and insert it to tbl_b (as FK).

In the end, tbl_a will have all the combination the three Dropdown List can offer so checking if raw exist in this table will not be necessary.

In my opinion this is not effective way to do that.
Can someone offer me better way to do it?

Thanks

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved