| Author |
Topic |
|
no_tofu_speed
Starting Member
6 Posts |
Posted - 2008-08-29 : 15:20:26
|
| This question is about a stored procedure that is an extension on the last one I asked help about, which just displayed the current status of each item.http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=109707(Thanks for the help Vinnie881)This stored procedure is designed to:Show the status history of each item. Displaying the changes in ‘status’ followed by the ‘status date’, for a specified item by an item identifying parameter.Orders of status are:Request > Authorized > Order > Delivered OrRequest > DeniedIn the case of ‘Cancelled’A Cancel can occur after Authorized or it can occur after OrderRequest > Authorized > CancelledOrRequest > Authorized > Order > CancelledThis is the reason why for the nested CASE with an EXIST (not sure if this can be done).To test if the process is cancelled after Authorized, or if it was cancelled after an Order (if an Order for the item exists), and displays the appropriate history, to include an Order status and Date if it has one, before a Cancel status and date.[Req_status = 'Requested'] Create new field called Req_status displaying the text ‘Requested’, in that position in the code.(I do not remember how to)All dates want to keep their display column name as their original column name in the tables... hence.r.Req_date AS Req_date[Exception Ord_cancel_date AS Canc_date]Any help would be appreciated thankyou.. |
|
|
no_tofu_speed
Starting Member
6 Posts |
Posted - 2008-08-29 : 15:22:11
|
| CREATE PROCEDURE usp_Read_request_status_history@item_Ident nvarchar(12)ASSELECT i.Item_id, i.Title,CASE WHEN r.Status = 'Requested' THEN [Req_status = 'Requested'], r.Req_date AS Req_date WHEN r.Status = 'Authorized' THEN(SELECT top 1 [Req_status = 'Requested'], r.Req_date AS Req_date, [Auth_status = 'Authorized'], au.Auth_date AS Auth_date FROM dbo.Request r, dbo.Auth_request au WHERE r.Item_id = au.Item_id) WHEN r.Status = 'Denied' THEN (SELECT top 1 [Req_status = 'Requested'], r.Req_date AS Req_date, [Deny_status = 'Denied'], dr.Deny_date AS Deny_date FROM dbo.Request r, dbo.Deny_request dr WHERE r.Item_id = dr.Item_id) WHEN r.Status = 'Ordered' THEN(SELECT top 1 [Req_status = 'Requested'], r.Req_date AS Req_date, [Auth_status = 'Authorized'], au.Auth_date AS Auth_date, [Ord_status = 'Ordered'], o.Order_date AS Order_date FROM dbo.Request r, dbo.Auth_request au, dbo.[Order] o WHERE r.Item_id = o.Item_idAND r.Item_id = au.Item_id) WHEN r.Status = 'Cancelled' THEN(SELECT top 1 Req_status = 'Requested'], r.Req_date AS Req_date, [Auth_status = 'Authorized'], au.Auth_date AS Auth_dateCASE WHEN EXISTS (SELECT o.Item_id FROM dbo.[Order] o WHERE o.Item_id = @item_Ident) THEN[Ord_status = 'Ordered'], dbo.[Order].Order_date, FROMdbo.[Order] oWHERE r.Item_id = o.Item_id END[Can_status = 'Cancelled'], oc.Ord_cancel_date AS Canc_dateFROM dbo.Request r, dbo.Auth_request au, dbo.Order_cancel ocWHERE r.Item_id = au.Item_id AND r.Item_id = oc.Item_id)WHEN r.Status = 'Delivered' THEN(SELECT top 1 Req_status = 'Requested'], r.Req_date AS Req_date, [Auth_status = 'Authorized'], au.Auth_date AS Auth_date, [Ord_status = 'Ordered'], o.Order_date AS Order_date, [Del_status = 'Delivered'], ar.Arrival_date AS Arrival_date FROM dbo.Request r, dbo.Auth_request au, dbo.[Order] o, dbo.Arrival ar WHERE r.Item_id = ar.Item_idAND r.Item_id = o.Item_idAND r.Item_id = au.Item_id) END FROM dbo.Item I INNER JOIN dbo.Request r ON i.Item_id = r.Item_idWHERE r.Item_id = @item_Ident |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-30 : 02:27:54
|
| give your table sample data and also sample output |
 |
|
|
no_tofu_speed
Starting Member
6 Posts |
Posted - 2008-08-30 : 06:04:06
|
| Depending on the item_id given as a paramter, the result will be either one of these.(The top line is the column names, bottom line is displayed data. The "Status" fields before each date have to be created (I do not remember how to create a new column name)Item_id, Title, Req_status, Req_date, Deny_status, Deny_Dateitem001, Java Basics, Requested, 1/03/2008 12:00:00 AM, Denied, 2/03/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_date, Cancel_status, Canc_dateitem002, Advanced VB.NET, Requested, 3/03/2008 12:00:00 AM, Authorized, 4/03/2008 12:00:00 AM, Cancelled, 6/03/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_date, Ord_status, Order_date, Cancel_status, Canc_dateitem003, Studio Sound Effects, Requested, 4/03/2008 12:00:00 AM, Authorized, 5/03/2008 12:00:00 AM, Ordered, 30/03/2008 12:00:00 AM, Cancelled, 5/04/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_date, Ord_status Order_dateitem004, Multimedia Productions, Requested, 9/03/2008 12:00:00 AM, Authorized, 10/03/2008 12:00:00 AM, Ordered, 30/03/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_date, Ord_status, Order_date,item005, System Methodogies, Requested, 9/03/2008 12:00:00 AM, Authorized, 10/03/2008 12:00:00 AM, Ordered, 30/03/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_date, Ord_status, Order_date, Del_status, Arrival_dateitem006, e-Business - a Technological View, Requested, 10/03/2008 12:00:00 AM, Authorized, 11/03/2008 12:00:00 AM, Ordered, 30/03/2008 12:00:00 AM, Delivered, 20/04/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_date, Ord_status, Order_date, Del_status, Arrival_dateitem007, United Process Methodology - extensive guide, Requested, 12/03/2008 12:00:00 AM, Authorized, 13/03/2008 12:00:00 AM, Ordered, 30/03/2008 12:00:00 AM, Delivered, 22/04/2008 12:00:00 AMItem_id, Title, Req_status, Req_date, Auth_status, Auth_dateitem008, SQL Server 2005 - intermediate, Requested, 13/03/2008 12:00:00 AM, Authorized, 14/03/2008 12:00:00 AM |
 |
|
|
no_tofu_speed
Starting Member
6 Posts |
Posted - 2008-08-30 : 06:04:33
|
| And here is a .bak file of my database.http://www.2shared.com/file/3847344/ff4386ea/INFT3009_ASS1_C2110574.html |
 |
|
|
|
|
|