Solved

Store Procedure

Posted on 2012-03-26
4
260 Views
Last Modified: 2012-03-26
Guys, Does someone could me help with mu store procedure.

The problem is , always is returning a 999 means that the store procedure did not find the product. But when i run the select out of storeprocedure i can find the product.

Is is some thing wrong in this SP ?

Thanks guys


-------------------------
ALTER procedure [dbo].[CreatePickHelper]
(
       @Sku varchar,
       @Total int out
)       
as
declare @LocationsAvaliable int = 0;
declare @HoldOnStock int = 0;
declare @OrdersAlreadyCreated int = 0;
declare @ProductID int;
begin
          -- get the ProductId
          set @ProductID = isnull((select distinct id from product where upper(product.sku) = upper(@Sku)),0);
         
              -- get the QTD Locations Avaliable to pick
             
              if(@ProductID > 0)  
              begin
                    set @LocationsAvaliable = isnull(( select
                                                                        sum(qtd) as Total
                                                              from
                                                                        StockLocations as S
                                                              where locationID in ( select Id from locations where locationFlag_id in
                                                                                            ((select id from locationflag where ispickable = 1 )))
                                                                        and productId = @ProductID),0)
                   -- Get the QTD on pick on Hold                                                                    
                                            
                    set @HoldOnStock = isnull((select
                                                              sum(qtd)
                                                      from  pickingdetail
                                                      where pick_id in (select pick from HoldStock) and pickingdetail.product_id = @ProductID ),0)
              
                   -- Get the QTD on orders different of Canceled or Completed
              
                   set @OrdersAlreadyCreated = isnull(( select
                                                                          sum(qtd) - sum(qtd_picked) as TotalAlreadyCreated
                                                               from pickingdetail
                                                               where pick_id in (
                                                                                            select id from picking where order_id in (
                                                                                            select order_id from orderheader where OrderStatus not in(6,12)))
                                                                          ),0)
                                                                         
                 set @Total = @LocationsAvaliable - @HoldOnStock - @OrdersAlreadyCreated ;
               end  
               else      
                set @Total = 999;
end
0
Comment
Question by:Mortarello
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:Mortarello
ID: 37765374
Is returning [0] on this line guyz

set @ProductID = isnull((select distinct id from product where upper(product.sku) = upper(@Sku)),0);

when I try this manually works.
0
 
LVL 14

Accepted Solution

by:
Christopher Gordon earned 500 total points
ID: 37765480
Is your variable declared correctly?

  @Sku varchar,

This assumes that the SKU is one character long.

Try something like this to see if it works

  @Sku varchar(50)
0
 
LVL 13

Expert Comment

by:Ashok
ID: 37765489
Try changing syntax of IsNull

set @ProductID = select distinct isnull(id,0) from product where upper(product.sku) = upper(@Sku);

Do same for other IsNull.....

HTH
Ashok
0
 

Author Comment

by:Mortarello
ID: 37765562
Hi guys,

Thanks for that. The sku should be varchar(40).

Tks man
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question