jeroenSturm
Gebruiker
- Lid geworden
- 2 mei 2012
- Berichten
- 197
waarom geeft hij de fout
[SQL]USE twijnentest
go
CREATE function [selecteer_alles]() RETURNS TABLE
AS
RETURN (
DECLARE @totalRecords INT
DECLARE @I INT
SELECT @I = 1
SELECT @totalRecords = COUNT([Id]) FROM [dbo].[Werkzaamheden]
WHILE (@I <= @totalRecords)
BEGIN
SELECT
U.[Id]
, G.[Naam]
, W.[Omschrijving]
, U.[datum]
, CONVERT(VARCHAR,100)+'%' AS 'Status'
, W.[Norm]
, W.Id
FROM [Werkzaamheden] W
RIGHT JOIN [Uitgevoerd] U ON U.[Taak] = W.[Id] /*or left */
FULL JOIN [Gebruikers] G ON G.[Naam] = U.[Naam]
WHERE U.[Status]= 1 AND W.Id = @I
UNION
SELECT
U.[Id]
, G.[Naam]
, W.[Omschrijving]
, U.[datum]
, CONVERT(VARCHAR,0)+'%' AS 'Status'
, W.[Norm]
, W.Id
FROM [Werkzaamheden] W
LEFT JOIN [Uitgevoerd] U ON U.[Taak] = W.[Id] /*or left */
FULL JOIN [Gebruikers] G ON G.[Naam] = U.[Naam]
WHERE U.[Status]= 0 AND W.Id = @I
UNION
SELECT
U.[Id]
, G.[Naam]
, W.[Omschrijving]
, U.[datum]
, null AS 'Status'
, '' AS Norm
, W.Id
FROM [Werkzaamheden] W
RIGHT JOIN [Uitgevoerd] U ON U.[Taak] = W.[Id] /*or left */
FULL JOIN [Gebruikers] G ON G.[Naam] = U.[Naam]
WHERE U.[Status]IS NULL
SELECT @I = @I + 1
END
)[/SQL]
Msg 156, Level 15, State 1, Procedure selecteer_alles, Line 6
Incorrect syntax near the keyword 'DECLARE'.
[SQL]USE twijnentest
go
CREATE function [selecteer_alles]() RETURNS TABLE
AS
RETURN (
DECLARE @totalRecords INT
DECLARE @I INT
SELECT @I = 1
SELECT @totalRecords = COUNT([Id]) FROM [dbo].[Werkzaamheden]
WHILE (@I <= @totalRecords)
BEGIN
SELECT
U.[Id]
, G.[Naam]
, W.[Omschrijving]
, U.[datum]
, CONVERT(VARCHAR,100)+'%' AS 'Status'
, W.[Norm]
, W.Id
FROM [Werkzaamheden] W
RIGHT JOIN [Uitgevoerd] U ON U.[Taak] = W.[Id] /*or left */
FULL JOIN [Gebruikers] G ON G.[Naam] = U.[Naam]
WHERE U.[Status]= 1 AND W.Id = @I
UNION
SELECT
U.[Id]
, G.[Naam]
, W.[Omschrijving]
, U.[datum]
, CONVERT(VARCHAR,0)+'%' AS 'Status'
, W.[Norm]
, W.Id
FROM [Werkzaamheden] W
LEFT JOIN [Uitgevoerd] U ON U.[Taak] = W.[Id] /*or left */
FULL JOIN [Gebruikers] G ON G.[Naam] = U.[Naam]
WHERE U.[Status]= 0 AND W.Id = @I
UNION
SELECT
U.[Id]
, G.[Naam]
, W.[Omschrijving]
, U.[datum]
, null AS 'Status'
, '' AS Norm
, W.Id
FROM [Werkzaamheden] W
RIGHT JOIN [Uitgevoerd] U ON U.[Taak] = W.[Id] /*or left */
FULL JOIN [Gebruikers] G ON G.[Naam] = U.[Naam]
WHERE U.[Status]IS NULL
SELECT @I = @I + 1
END
)[/SQL]
Laatst bewerkt door een moderator: