August 29, 2017 at 7:51 am
i would like to create a stored procedure to find the Top Level Demand for a Supply .
I have a stored procedure which gives the demand for the passed Supply Matl Tag. Aim is to loop through this stored procedure to find the top level Demand.
Note that Each Supply could have one or multiple demands.
So at the end we might come up with multiple Top Level Demand for a given supply.
the stored procedure accept one parameter Supply ID :
exec GetSupplyDemand 'SupplyID'
1.
create table tt-matl
DemandID as int
2. create table by executing stored procedure GetSupplyDemand
insert into tt-matl
exe c GetSupplyDemand matltag = 100
3. Loop through tt-matl table and execute the stored procedure GetSupplyDemand
August 29, 2017 at 7:56 am
Okay, but you used the words "top level" without defining exactly what that means in your environment. We can't even guess as you've provided no useful context. Assuming you have a stored procedure that gets all the demand values for a given Supply Material Tag value, doesn't really give us enough to go on. From those available values, what makes any given value "top level" ?
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
August 29, 2017 at 9:05 am
As Steve noted, your terminology makes no sense from the outside. We don't know your business, so the Supply Mtl Tag and demand have no context. We'd need some explanation of what these terms mean for the data relationships.
However, your text seems to indicate that you want to work in a serial, row by row fashion. In SQL , we want to think about working with a big set of data all at once.
August 29, 2017 at 9:52 am
Here is the Example
Customer Order Line :
ORD00001 - 1
--JOB- JOB0001
----JOB-JOB0002
------JOB-JOB0003
--------JOB-JOB0004
----------MATERIAL-Matl01
ORD09999 - 1
--JOB- JOB0001
----JOB-JOB0002
------JOB-JOB0003
--------JOB-JOB0004
----------MATERIAL-Matl01
If I want to find the Top Level Demand for MATERIAL-Matl01 , My Result should be - ORD00001-1, ORD09999-1
if I run exec GetSupplyDemand 'MATERIAL-Matl01' I will get result 'JOB-JOB0004'.
August 29, 2017 at 10:28 am
Your indentation doesn't make sense from a db perspective. Are these separate lines? a separate table of data? What is a demand, and what does "top" mean? Is this ordering by largest job number? Date?
The two results you give don't make sense. How do you arrive at the rules for producing those results?
August 29, 2017 at 11:12 am
I don't know the DB detail. The Stored procedure gives the list of demand for the supplied SupplierID. We just keep looping thru until we don't find Demand for the Supply and that becomes Top Level Demand.
In our examples :
Customer Order Line :
ORD00001 - 1
--JOB- JOB0001
----JOB-JOB0002
------JOB-JOB0003
--------JOB-JOB0004
----------MATERIAL-Matl01
So the program should loop for
exec GetSupplyDemand 'MATERIAL-Matl01' - Output will be JOB-JOB0004
exec GetSupplyDemand 'JOB-JOB0004'- Output will be JOB-JOB0003
exec GetSupplyDemand 'JOB-JOB0003'- Output will be JOB-JOB0002
exec GetSupplyDemand 'JOB-JOB0002'- Output will be JOB-JOB0001
exec GetSupplyDemand 'JOB-JOB0001'- Output will be ORD00001 - 1.
exec GetSupplyDemand 'ORD00001 - 1'- Output will be NULL
So program will stop here and give Top Level Demand as 'ORD00001 - 1'
August 29, 2017 at 2:56 pm
Thanks for the reply. The problem is the output of the stored procedure is a dataset and it could have multiple demand. If there a one demand for a supplyid the. Code will work fine.
August 29, 2017 at 3:06 pm
If there are multiple items, how are they returned? Is this a text stream, or are these separate rows being returned? The output is a datatable/result set of some sort, with rows and columns. It can probably be parsed, but that's a highly inefficient use of SQL Server resources. Your front end application code is better suited to handle some of this.
August 29, 2017 at 3:31 pm
skb 44459 - Tuesday, August 29, 2017 11:12 AMI don't know the DB detail. The Stored procedure gives the list of demand for the supplied SupplierID. We just keep looping thru until we don't find Demand for the Supply and that becomes Top Level Demand.
In our examples :
Customer Order Line :
ORD00001 - 1
--JOB- JOB0001
----JOB-JOB0002
------JOB-JOB0003
--------JOB-JOB0004
----------MATERIAL-Matl01
So the program should loop for
exec GetSupplyDemand 'MATERIAL-Matl01' - Output will be JOB-JOB0004
exec GetSupplyDemand 'JOB-JOB0004'- Output will be JOB-JOB0003
exec GetSupplyDemand 'JOB-JOB0003'- Output will be JOB-JOB0002
exec GetSupplyDemand 'JOB-JOB0002'- Output will be JOB-JOB0001
exec GetSupplyDemand 'JOB-JOB0001'- Output will be ORD00001 - 1.
exec GetSupplyDemand 'ORD00001 - 1'- Output will be NULLSo program will stop here and give Top Level Demand as 'ORD00001 - 1'
Can you post the code for the GetSuppyDemand stored procedure?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply