I'm trying to create a function in SQL Server 2000 and i'm having the error message: Incorrect syntax near the keyword 'SET'.
I've tried but i can't fix this. does anybody can help me?
Here is the code:
CREATE FUNCTION fMelhor_precisao_hora
( @veiculo nvarchar(50),
@data_inicio datetime,
@data_fim datetime )
RETURNS @Pontos_no_intervalo TABLE
( latitude nvarchar(50),
longitude nvarchar(50),
data datetime,
hora int )
AS
BEGIN
WHILE ( @data_inicio <= @data_fim )
BEGIN
INSERT @Pontos_no_intervalo
SELECT latitude, longitude, dtponto, DATEPART ( hh, @data_inicio ) as hora
FROM tpontos
WHERE id_veiculo = @veiculo AND dtponto = @data_inicio
GROUP BY hora
HAVING MIN ( precisao )
SET @data_inicio = DATEADD ( dd, 1, @data_inicio )
END
RETURN
END
GO
I've tried but i can't fix this. does anybody can help me?
Here is the code:
CREATE FUNCTION fMelhor_precisao_hora
( @veiculo nvarchar(50),
@data_inicio datetime,
@data_fim datetime )
RETURNS @Pontos_no_intervalo TABLE
( latitude nvarchar(50),
longitude nvarchar(50),
data datetime,
hora int )
AS
BEGIN
WHILE ( @data_inicio <= @data_fim )
BEGIN
INSERT @Pontos_no_intervalo
SELECT latitude, longitude, dtponto, DATEPART ( hh, @data_inicio ) as hora
FROM tpontos
WHERE id_veiculo = @veiculo AND dtponto = @data_inicio
GROUP BY hora
HAVING MIN ( precisao )
SET @data_inicio = DATEADD ( dd, 1, @data_inicio )
END
RETURN
END
GO