Solved

Store Procedure

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

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 …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

840 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