Showing posts with label lines. Show all posts
Showing posts with label lines. Show all posts

Tuesday, March 20, 2012

A tree of location and site names..

Hello,
This is a tuff one not sure if it can be done with an SQL query, I'm
thinking along the lines of an inner join, but I'm not really sure.
I have a table that is used to refer to location_names as nodes and sites as
the leaf nodes it is the site names that I want to return based on a join to
another table using the SiteFK column.
TABLE: TRS_SiteTree
SiteTreePK ParentFK Name SiteFK Path
1 0 All 0
0
2 1 South 0
0.0
3 1 North 0
0.1
4 2 Oxfordshire 0
0.0.0
5 4 Witney 1
0.0.0.0
6 4 Banbury 2
0.0.0.1
7 3 Teeside 0
0.1.0
8 7 Yarm 3
0.1.0.0
9 4 Oxford 4
0.0.0.2
10 3 Yorkshire 5
0.1.1
The SiteFK indicates if the site is a leaf node if it is <> 0 otherwise a
parent
The Path indicates the level of nesting
The leaf node Yorkshire has a parentFK of 3 which matches to the SiteTreePK
of 3 which subsequently has a Parent FK of 1 and a location of North which
sits under All where the Parent FK matches with the SiteTreePK of 1 All.
An illustration of the tree that the table represents:
0 All
|_____0.0 South
| |______0.0.0 Oxfordshire
| |_________ 0.0.0.0 Witney
(leaf 1)
| |_________ 0.0.0.1 Banbury
(leaf 2)
| |_________ 0.0.0.2 Oxford
(leaf 4)
|_____ 0.1 North
|______ 0.1.0 Teeside
| |_________ 0.1.0.0 Yarm (leaf
3)
|______ 0.1.1 Yorkshire (leaf 5)
if you have any suggestions on where I might start with this task this would
be muchly appreciated even if it's just a few ideas to try out.
Thank you kindly
Rhonda
ooops, I mean a self join
"Rhonda Fischer" wrote:

> Hello,
> This is a tuff one not sure if it can be done with an SQL query, I'm
> thinking along the lines of an inner join, but I'm not really sure.
> I have a table that is used to refer to location_names as nodes and sites as
> the leaf nodes it is the site names that I want to return based on a join to
> another table using the SiteFK column.
> TABLE: TRS_SiteTree
> SiteTreePK ParentFK Name SiteFK Path
> 1 0 All 0
> 0
> 2 1 South 0
> 0.0
> 3 1 North 0
> 0.1
> 4 2 Oxfordshire 0
> 0.0.0
> 5 4 Witney 1
> 0.0.0.0
> 6 4 Banbury 2
> 0.0.0.1
> 7 3 Teeside 0
> 0.1.0
> 8 7 Yarm 3
> 0.1.0.0
> 9 4 Oxford 4
> 0.0.0.2
> 10 3 Yorkshire 5
> 0.1.1
> The SiteFK indicates if the site is a leaf node if it is <> 0 otherwise a
> parent
> The Path indicates the level of nesting
> The leaf node Yorkshire has a parentFK of 3 which matches to the SiteTreePK
> of 3 which subsequently has a Parent FK of 1 and a location of North which
> sits under All where the Parent FK matches with the SiteTreePK of 1 All.
> An illustration of the tree that the table represents:
> 0 All
> |_____0.0 South
> | |______0.0.0 Oxfordshire
> | |_________ 0.0.0.0 Witney
> (leaf 1)
> | |_________ 0.0.0.1 Banbury
> (leaf 2)
> | |_________ 0.0.0.2 Oxford
> (leaf 4)
> |_____ 0.1 North
> |______ 0.1.0 Teeside
> | |_________ 0.1.0.0 Yarm (leaf
> 3)
> |______ 0.1.1 Yorkshire (leaf 5)
> if you have any suggestions on where I might start with this task this would
> be muchly appreciated even if it's just a few ideas to try out.
> Thank you kindly
> Rhonda
>
|||On Fri, 13 May 2005 08:22:02 -0700, Rhonda Fischer wrote:

>Hello,
>This is a tuff one not sure if it can be done with an SQL query, I'm
>thinking along the lines of an inner join, but I'm not really sure.
(snip)
Hi Rhonda,
Sorry for the late reply.
I'm not sure what exactly you're asking. Your message doesn't appear to
have any specific question. Are you looking for generic advice if your
solution is the best one for your problem? Or do you actually need a
query to do a specific job?
In the latter case, please repost. I'd appreciate it if you'd post the
table structure as a CREATE TABLE statement (including all constraints
and properties - any irrelevant columns may be left out, though) and the
sample data as INSERT statements. Also, post the output you'd like to
get from the sameple data.
Check www.aspfaq.com/5006 for some useful hints on how to post.
If you're looking for generic advice on how to deal with hierarchies,
then your best bet is to buy and read "Trees and Hierarchies in SQL" by
Joe Celko. This book describes several ways to model a hierarchy in SQL,
with their pros and cons.
You could also google for "nested sets model" and "adjacency list model"
to find information about two of the most common ways to represent a
hierarchy.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Dear Hugo,
Thank you very much for your considered thought on my questions. Your
thoughts and suggested reference material were helpful to draw this to a
resolution.
Thank you again
Cheerio
Rhonda
"Hugo Kornelis" wrote:

> On Fri, 13 May 2005 08:22:02 -0700, Rhonda Fischer wrote:
> (snip)
> Hi Rhonda,
> Sorry for the late reply.
> I'm not sure what exactly you're asking. Your message doesn't appear to
> have any specific question. Are you looking for generic advice if your
> solution is the best one for your problem? Or do you actually need a
> query to do a specific job?
> In the latter case, please repost. I'd appreciate it if you'd post the
> table structure as a CREATE TABLE statement (including all constraints
> and properties - any irrelevant columns may be left out, though) and the
> sample data as INSERT statements. Also, post the output you'd like to
> get from the sameple data.
> Check www.aspfaq.com/5006 for some useful hints on how to post.
> If you're looking for generic advice on how to deal with hierarchies,
> then your best bet is to buy and read "Trees and Hierarchies in SQL" by
> Joe Celko. This book describes several ways to model a hierarchy in SQL,
> with their pros and cons.
> You could also google for "nested sets model" and "adjacency list model"
> to find information about two of the most common ways to represent a
> hierarchy.
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>

Monday, February 13, 2012

A lot of sp_cursorfetch in profiler.

Hi all.
I am looking at some profiler logging and gets a lot of the lines looking
like:
exec sp_cursorfetch 180150024, 2, 0, 1
This comes after running a simple prosedure that select some lines.
All i VB6. I guess it has something to do on how we retrieve data (ADO).
Does anyone have a few hints on where to look to get rid of all these lines.
Or what to try.
thanx all.
geirYou should open a "firehose" cursor, AKA "default resultset", AKA adOpenForw
ardOnly (try this
attribute on your recordset).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Geir Holme" <geir@.multicase.no> wrote in message news:OQ2SDd0EFHA.3536@.TK2MSFTNGP15.phx.gb
l...
> Hi all.
> I am looking at some profiler logging and gets a lot of the lines looking
like:
> exec sp_cursorfetch 180150024, 2, 0, 1
>
> This comes after running a simple prosedure that select some lines.
> All i VB6. I guess it has something to do on how we retrieve data (ADO). D
oes anyone have a few
> hints on where to look to get rid of all these lines. Or what to try.
>
> thanx all.
> geir
>|||sp_cursorfetch is a pseudo stored procedure (server internal) used by OLE
DB, ODBC, ADO, and DB-Library APIs which map cursors over the result sets of
executed SQL statements. Check the cursor type and locking mode of your
cursor to investigate any performance problems. A quick search on SQL Server
BOL will give you more idea on sp_cursorfetch. Read topic "API Server
Cursors" ...
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
"Geir Holme" <geir@.multicase.no> wrote in message
news:OQ2SDd0EFHA.3536@.TK2MSFTNGP15.phx.gbl...
> Hi all.
> I am looking at some profiler logging and gets a lot of the lines looking
> like:
> exec sp_cursorfetch 180150024, 2, 0, 1
>
> This comes after running a simple prosedure that select some lines.
> All i VB6. I guess it has something to do on how we retrieve data (ADO).
> Does anyone have a few hints on where to look to get rid of all these
lines.
> Or what to try.
>
> thanx all.
> geir
>