views:

172

answers:

3

This Codes give me error:
Msg 156, Level 15, State 1, Procedure DefaultActivity, Line 2 Incorrect syntax near the keyword 'RETURN'. Msg 137, Level 15, State 2, Procedure DefaultActivity, Line 3 Must declare the scalar variable "@returnTable". Msg 1087, Level 15, State 2, Procedure DefaultActivity, Line 18 Must declare the table variable "@returnTable".

CREATE FUNCTION dbo.DefaultActivity
RETURNS
    @returnTable table (
[VisitingCount] int,
[Time] nvarchar(50)
)

AS
BEGIN

DECLARE @DateNow DATETIME,@i int
set @DateNow='00:00'
set @i=1;

    while(@i<1440)
     begin
      set @DateNow=DATEADD(minute, 1, @DateNow)
       insert into @returnTable ([VisitingCount], [Time]) values(0, right(left(convert(nvarchar, @DateNow, 121), 16), 5))
      set @i=@i+1
     end

    RETURN
END
A: 

I guess it should be

CREATE FUNCTION dbo.DefaultActivity()
RETURNS                    -- RETURN vs RETURNS here
Scoregraphic
i change it. but result is as same as before.
Phsika
+3  A: 

Try specifying an empty argument list?

CREATE FUNCTION dbo.DefaultActivity()
RETURNS
...
Andomar
that's it - but it seems the OP needed a "copy and paste" solution
kristof
+1. Your solution is correct, I just ran the entire thing to make sure no other errors were made.
edosoft
A: 

This should work:

CREATE FUNCTION dbo.DefaultActivity ()
RETURNS @returnTable 
TABLE 
(
  [VisitingCount] int,
  [Time] nvarchar(50)
) 
AS
BEGIN
    DECLARE @DateNow DATETIME,@i int

    set @DateNow='00:00'
    set @i=1;

    while(@i<1440)
        begin
                set @DateNow=DATEADD(minute, 1, @DateNow)
                insert into @returnTable ([VisitingCount], [Time]) 
       values(0, right(left(convert(nvarchar, @DateNow, 121), 16), 5))
                set @i=@i+1
        end

    RETURN
END

GO

select * from dbo.DefaultActivity()
edosoft
you are not correct. i need table look codes please!!!
Phsika
thanks alot!!! you solved it...
Phsika
@ykaratoprak - the question was answered correctly by Andomar as well (you only needed to add brackets) He did not post the full code though
kristof