Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Store Procedure

Posted on 2012-03-26
4
Medium Priority
?
263 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 2000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

636 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