Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Views and Cursors

Author  Topic 

wotrac
Yak Posting Veteran

98 Posts

Posted - 2005-04-17 : 05:44:58
Is it possible to create a view using a cursor?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-04-17 : 07:57:20
No, and why would you want to?
Go to Top of Page

wotrac
Yak Posting Veteran

98 Posts

Posted - 2005-04-17 : 09:48:50
I thought I might be able to resolve my problem by using a cursor, but wanted the resulting data to be available in a view, as the underlying data is changing constantly.

If I explain the problem, could you suggest a better way of achieving the desired result.

I have a table of stock assemblies, as below.
I already know which code is at level one, but need to identify the levels of the other components.



PRIMARY PARTCODE STOCK_CODE LEVEL
1 acode1 stkcode1 LvL1
2 acode2 stkcode1 LvL1
3 acode1 stkcode2 LvL1
4 acode3 stkcode2 LvL1
5 bcode1 acode1
6 bcode2 acode1
7 ccode1 bcode1
8 ccode2 bcode2
9 dcode1 ccode1

If we take stkcode1 as the top level
The corresponding hierarchy will be

stcode1
.......acode1
.............bcode1
...................ccode1
.............bcode2
.......acode2


etc etc


What I want to achieve is the following

LEVEL_1 Level_2 Level_3 Level_4

stkcode1 acode1 bcode1 ccode1
stkcode1 acode2 Null Null


Could you suggest a quicker way of achieving this result
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-04-17 : 09:49:59
See if this helps:

http://www.sqlteam.com/item.asp?ItemID=8866
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2005-04-17 : 13:04:34
and
http://www.mindsdoor.net/SQLTsql/RetrieveTreeHierarchy.html
The table used to produce the results has the full path as a work column.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -