Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
SQL
CREATE function [dbo].[getRptOrders_test](@OrderNumber int)
returns table
as
RETURN
(
select case exists (select 1 from pf  where ordernumber = @OrderNumber) 
when 1 then 

      SELECT osc.tName, osc.VariantName, osc.Quantity,pf.RequestedDate, ISNULL(osc.Shipped, 0) AS TotalQtyShipped,
      case p.isakit
            when 1 then dbo.getKitPrice(osc.ShoppingCartRecID)
            else osc.OrderedProductPrice
      end
      as OrderedProductPrice, osc.ShoppingCartRecID, osc.Notes, p.IsAKit, osc.OrderNumber,o.CompanyID
      FROM Orders_ShoppingCart osc
      INNER JOIN  p ON osc.ProductID = p.ProductID
      INNER JOIN  o ON osc.OrderNumber = o.OrderNumber
      INNER JOIN   pitem ON osc.ShoppingCartRecID = pitem.ShoppingCartRecID
      INNER JOIN  pf ON pitem.POID = pf.POID
      WHERE (osc.OrderNumber = @OrderNumber) --and dbo.HasAKit(p.productID) = 1
      and osc.iskititem=0
      
      else 
      
       SELECT osc.tName, osc.VariantName, osc.Quantity, ISNULL(osc.Shipped, 0) AS TotalQtyShipped,
      case p.isakit
            when 1 then dbo.getKitPrice(osc.ShoppingCartRecID)
            else osc.OrderedProductPrice
      end
      as OrderedProductPrice, osc.ShoppingCartRecID, osc.Notes, p.IsAKit, osc.OrderNumber,o.CompanyID
      FROM Orders_ShoppingCart osc
      INNER JOIN  p ON osc.ProductID = p.ProductID
      INNER JOIN  o ON osc.OrderNumber = o.OrderNumber
      
      WHERE (osc.OrderNumber = @OrderNumber) --and dbo.HasAKit(p.productID) = 1
      and osc.iskititem=0
     
)
 

GO
Posted
Updated 19-Aug-14 23:11pm
v2
Comments
Ashi0891 20-Aug-14 5:11am    
where is the problem?
Magic Wonder 20-Aug-14 5:12am    
What is the issue?
venky1988 20-Aug-14 5:13am    
select case exists ..
case statement not working
Herman<T>.Instance 20-Aug-14 5:14am    
use functions for these queries and call the functions from this query
venky1988 20-Aug-14 5:19am    
CREATE function [dbo].[getRptOrders_test](@OrderNumber int)
returns table
as
RETURN
(
select case exists (select 1 from pf where ordernumber = @OrderNumber)
when 1 then
[dbo].[getRptOrders](@OrderNumber int)


else

[dbo].[getRptOrders_withoutpo](@OrderNumber int)

)


GO



here it is giving 2 errors 1. Incorrect syntax near the keyword 'exists'

2.Incorrect syntax near the keyword 'when'

Use this
SQL
CREATE function [dbo].[getRptOrders_test](@OrderNumber int)
returns table
as
RETURN
(
select case when exists (select 1 from pf  where ordernumber = @OrderNumber)
then
 
Share this answer
 
Comments
venky1988 20-Aug-14 5:33am    
this seems to be working , Thank you
Vinay Mistry 20-Aug-14 5:45am    
Good to hear that. and welcome.
venky1988 20-Aug-14 5:54am    
CREATE function [dbo].[getRptOrders_COH](@OrderNumber int)
returns table
as
RETURN
(

select case when exists (select 1 from po_form where ordernumber = @OrderNumber)
then
dbo.getRptOrders(@OrderNumber)

else

dbo.getRptOrdersWithoutPO(@OrderNumber)
end
)


GO



it is giving this error .. Cannot find either column "dbo" or the user-defined function or aggregate "dbo.getRptOrders", or the name is ambiguous.


can i Pass table valued functions . or this error is with input
Vinay Mistry 20-Aug-14 6:40am    
Try to call your functions without dbo. I don't have all the details otherwise I can check it myself.
venky1988 20-Aug-14 6:43am    
in other table valued functions they are calling with dbo.functionname
Hi,

Try this...


SQL
select case WHEN  exists (select 1 from pf  where ordernumber = @OrderNumber)
then 1 ...



Hope this will help you.


Cheers
 
Share this answer
 
Comments
venky1988 20-Aug-14 5:34am    
this seems to be working , Thank you
Magic Wonder 20-Aug-14 5:37am    
Your welcome.
Vinay Mistry 20-Aug-14 5:45am    
After then why need 1?
Magic Wonder 20-Aug-14 5:51am    
you can replace the same with your desired result.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900