I am getting this error
Msg 201, Level 16, State 4, Procedure sp_GetAllAirports, Line 0 [Batch Start Line 2]
Procedure or function 'sp_GetAllAirports' expects parameter '@AirportID', which was not supplied."
When I run
EXEC sp_GetAllAirports
The following is my stored procedure which shows @AirportID, what could be the issue?
IF OBJECT_ID('sp_GetAllAirports', 'P') IS NOT NULL
DROP PROCEDURE [dbo].[sp_GetAllAirports]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[sp_GetAllAirports]
@AirportID INT,
@ICAOCode VARCHAR(4) NULL,
@AirportName VARCHAR(MAX),
@City VARCHAR(MAX),
@Lat DECIMAL(8,3),
@Long DECIMAL (11,3),
@Elevation INT,
@Country NVARCHAR(MAX)
AS
BEGIN TRANSACTION
BEGIN TRY
SET NOCOUNT ON
SET ANSI_WARNINGS OFF
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
--SELECT * FROM tbl_Airports ORDER BY AirportID ASC
SELECT
AirportID, ICAOCode, AirportName, City,
Latitude, Longitude, Elevation, CountryFK
FROM
tbl_Airports
LEFT JOIN
tbl_Countries ON CountryID = tbl_Airports.CountryFK
WHERE
CountryID = tbl_Airports.CountryFK
ORDER BY
AirportID
END TRY
BEGIN CATCH
DECLARE @ErMessage NVARCHAR(MAX),
@ErSeverity INT,
@ErState INT
SELECT
@ErMessage = ERROR_MESSAGE(),
@ErSeverity = ERROR_SEVERITY(),
@ErState = ERROR_STATE()
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK TRANSACTION
END
RAISERROR(@ErMessage, @ErSeverity, @ErState)
END CATCH
IF @@TRANCOUNT > 0
BEGIN
COMMIT TRANSACTION
END
GO
sp_GetAllAirports 1234) or give it a default (@AirportID INT = 1234)?. Your Stored Procedure expects arguments. (AirportID,ICAOCode,AirportName,City,Lat,Long,ElevationandCountry) though it doesn't use any of them. You're better off removing the arguments so you won't have to pass any either. - RobIIIsp_prefix when naming procedures. This prefix is used by SQL Server to designate system procedures. Using the prefix can cause application code to break if there is a system procedure with the same name." As well as performance issues. - HABO