Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
create function cyl_receipt_details_func
(
@cylinder_no_get int
)
AS
RETURN
SELECT
 cylinder_no,supplier_name,gas_type,receipt_date,dc_no,dc_date ,receipt_qty ,uom ,
flag ,tran_stat ,receipt_tran_date ,receipt_modified_date

FROM tbl_cyl_gas_main 

WHERE cylinder_no=@cylinder_no_get

it shows error :Incorrect syntax near the keyword 'AS'
Posted
Updated 4-Apr-14 7:42am
v2
Comments
Andrius Leonavicius 5-Apr-14 11:09am    
I don't know who downvoted my answer (solution 2), but I really would like to know why.

Correct it:
SQL
CREATE FUNCTION cyl_receipt_details_func (@cylinder_no_get int)
RETURNS TABLE
AS
RETURN
(
    SELECT
    cylinder_no,supplier_name,gas_type,receipt_date,dc_no,dc_date ,receipt_qty ,uom ,
    flag ,tran_stat ,receipt_tran_date ,receipt_modified_date
    FROM tbl_cyl_gas_main
    WHERE cylinder_no=@cylinder_no_get
)
GO
 
Share this answer
 
Check out CREATE FUNCTION[^] syntax.
 
Share this answer
 
Hi,

It should look like this:
SQL
CREATE FUNCTION cyl_receipt_details_func (@cylinder_no_get INT)
RETURNS TABLE
AS
    RETURN
      SELECT cylinder_no,
             supplier_name,
             gas_type,
             receipt_date,
             dc_no,
             dc_date,
             receipt_qty,
             uom,
             flag,
             tran_stat,
             receipt_tran_date,
             receipt_modified_date
      FROM   tbl_cyl_gas_main
      WHERE  cylinder_no = @cylinder_no_get;

Because it is a table-valued function, you have to use it like this:
SQL
SELECT * FROM cyl_receipt_details_func(@cylinder_no_get);
 
Share this answer
 
v2
Comments
Andrius Leonavicius 5-Apr-14 11:16am    
I don't know who downvoted my answer, but I really would like to know why.
SQL
create function cyl_receipt_details_func
(
@cylinder_no_get int
)
returns table
as
RETURN
(
SELECT
 cylinder_no,supplier_name,gas_type,receipt_date,dc_no,dc_date ,receipt_qty ,uom ,
flag ,tran_stat ,receipt_tran_date ,receipt_modified_date
 
FROM tbl_cyl_gas_main 
 
WHERE cylinder_no=@cylinder_no_get
);



just simple, Refer Table-valued Functions
 
Share this answer
 

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