sql server - User defined function with CASE statement -


I am very new to SQL Server Here I get the position of the order from the database STRDAT based on the various order dates I have entered I try to make UDF with case statement. Here's the code:

  use are on STRDAT GO set Object_id GO SET QUOTED_IDENTIFIER ANSI_NULLS (N'dbo.GetOrderStatus ', N'FN') IS NOT NULL DROP function dbo.GetOrderStatus; Create GO Function dbo.GetOrderStatus (@lngOrderID integer) varchar (50) as returning MyData (ReservedRate as ReservedDate, as ConfirmedDate conference, in the form of ProcessedDate Procs, as ProducedDate Prod, ShippedDate form the ship, select Start with CANC as as RefusingReason Refs, CancelledDate Where tbl_Order OrderID = @lngOrderID) GetOrderStatus = case when race is zero and conf zero and procs zero and output is zero and zero ship And CANC is zero and Refs is empty then not in 'Naujas' One CANC if not zero 'AtÃ…¡auktas' absence Refs zero is not being shipped to 'Atmestas' prod if not zero 'Atkrautas' is zero 'Pagamintas' in Procs is zero 'Apdirbtas' It is one of my first tasks and I can not explain why I get an error on the line  CREATE CREATION .. . :  

The selection of statements contained within the function can not return data to a customer.

  • Wrap the query in parentheses
  • Remove GetOrderStatus = < Li> / code>

    Try this: returns (with MyData ... select ... from mydata);


    BTW:

      When the race is zero and the conf is zero and the procs is zero and the output is zero and the ship is zero and the canc is zero and Refs blank   

    more can be displayed elegantly:

      when COALESCE (race, conf, procs, prod, ship, CANC, Refs) IS Null is    

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -