Solved

Store Procedure

Posted on 2012-03-26
4
259 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query Syntax 17 53
SQL Recursion 6 35
Using this function 4 43
Estimating my database size 7 21
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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