0

I have written following function in SQLServer 2005

Following is the function:

create function fnBillParticulars()
return table
as
return (select * from billParticulars where Id='2425')
go

Its giving me following errors:

1.Msg 156, Level 15, State 1, Procedure fnBillParticulars, Line 2
  Incorrect syntax near the keyword 'return'.

2.Msg 178, Level 15, State 1, Procedure fnBillParticulars, Line 4
  A RETURN statement with a return value cannot be used in this context.

what can be the mistake?

Please help me.

3 Answers 3

3

Please try:

create function fnBillParticulars()
returns table
as
return (select * from billParticulars where Id='2425')
go
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. , was unware about 'returns'. Thank you.
1

you can alternatively create a VIEW on this,

CREATE VIEW fnBillParticulars
AS
select * 
from billParticulars 
where where Id='2425'

or if you want table valued function

CREATE FUNCTION fnBillParticulars()
RETURNS @BillParticulars TABLE 
(
   Id       int,
   -- other columns here
) 
AS
BEGIN
   INSERT INTO @BillParticulars (Id, ...) -- specify columns here
    SELECT  * 
    FROM    billParticulars 
    WHERE   Id = '2425';

   RETURN;
END;

3 Comments

I know views, but Team Leader told me to get aquented with functions in SQL. Thanks for answer.
ohh, good, complecated, but came to know new things in function. Thanks
yeah. This was my first attempt for functions, will go for parameters now.
1

U written "where" Twice in the query.

query should be:

select * from billParticulars where Id='2425'

and use "returns" table

create function fnBillParticulars()
returns table
as
return (select * from billParticulars where Id='2425')
go

1 Comment

Tayade dada, where chukun donada ithe type zalay, aani thank you, returns sathi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.