sql - Nested cursors, multiple result sets -


I am using SQL Server stored procedure to generate Excel reports. Basically, each "entry" in the report has three parts: objects, observations and points. The comments are in reference to the primary key of an object, and there is a reference to an overview of the number. It is a connection between parts (sorry if my terminology is closed, then I am being used to write in C # or Java, but still I am learning SQL.)

I want to The output should be like this:

  - Object - All objects associated with that object - Under each observation, all points associated with that observation should be   

And repeat for each object. I am using a cursor to create all the comments with each object, but I can not get points to come under every observation

I have read all on the internet that the cursor Bad, and I think nested cursors are very bad but I still have it. If you know a better way to do this, please let me know. I am open to completely reconstructing this if necessary.

  announcement objects @Object_Cursor announced cursor @Observation_Cursor cursor Declaration for @i announced @j integer @row Integer = 1 set @Object_Cursor cursor = int (select PK_ObjectId) OPEN @ Object_Cursor FETCH while @ ahead of @Object_Cursor @@ FETCH_STATUS = Start select PK_ObjectID, name, select the timestamp of objects where PK_ObjectID = @i SET @ Objheshn_ Cursor = the CURSOR (SEK objection from @PK_ObservationID) OPEN @ Observation_Cursor @j Do not check next @Observation_Cursor while @@ FETCH_STATUS = 0 start timestamp , Notes, comments from users where FK_ObjectId = @i FK_ObjectID select Latitude, the points where ordered by Lng FK_ObservationID = Fetch @j Next @Observation_Cursor from @ Jay finally @i end off @Observation_Cursor deallocate @Observation_Cursor off @Object_Cursor deallocate @Object_Cursor Next Do not Launch From @Object_Cursor   

In some way I feel like the order I am executing these loops, but I'm not able to get it. The current output is:

  -Object- Observations for that object -mate point result set   

Repeated results for the same object several times First for the next one, and the points are always empty.

Any help or signal in any direction is greatly appreciated.

The C # loop argument is not how you want to think about SQL ... 1 The statement is always better.

I think this is closer to what you have ... I'm guessing some things in my keys.

  Select objects (pick up your fields here) items left from objects.PK_ObjectID = Observations.FK_ObjectID Pts.FK_ObservationID = observations.pk_observation_ID   Include comments when joining / div> 

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -