I want to put if condition for following query but getting error
ALTER PROCEDURE [dbo].[GetExternalDocumentHistory]
@reoid int,
@spType VARCHAR(50),
@maximumRows INT = 0,
@startRowIndex INT = 0,
@recordCount INT OUTPUT
AS BEGIN
DECLARE @data TABLE(
id INT IDENTITY(1,1),
property_address NVARCHAR(250),
property_id INT )
INSERT @data( property_address, property_id )
IF( @spType = 'ED' )
BEGIN
SELECT property_address, property_id
FROM external_documents_history as edu
WHERE edu.property_id = @reoid
END;
IF (@spType = 'GD' )
BEGIN
SELECT property_address, property_id
FROM external_documents_history as edu
WHERE edu.page_type = 'GD'
END;
SELECT @recordCount = COUNT(*) FROM @data
IF @maximumRows = 0
BEGIN
SET @startRowIndex = 0
SET @maximumRows = @recordCount
END
SELECT * FROM @data
WHERE id BETWEEN @startRowIndex + 1 AND @startRowIndex + @maximumRows
ORDER BY id
END;
What is the issue with the above query ?
INSERTstatement right above the if.