'SQL Stored Procedure Parameter set to Uppercase
I want to force a user's string input in a stored procedure to uppercase. I tried writing UPPER
prior to the @parameterName
but I got a syntax error. Is this possible? Would be it be better suited to convert the string to uppercase in the statement itself? Here's the code to my SP where I was attempting to use UPPER
in the parameter definition.
ALTER PROCEDURE [dbo].[UpdateEntries]
UPPER @ENTRY_TYPE NVARCHAR(20) = '',
UPPER @ENTRY_NAME NVARCHAR(50),
@CLASS_TYPE_ID INT,
@ENTRY_PRICE DEC(4,2),
@ENTRY_DESCRIPT NVARCHAR(max),
@PET_FRIENDLY BIT,
@AGE_RESTRICTION BIT,
@PRICE_RANGE_ID INT,
@RESTAURANT_TYPE_ID INT NULL
AS
BEGIN
SET NOCOUNT ON;
IF @ENTRY_TYPE = 'ACTIVITY'
BEGIN
UPDATE ACTIVITY_DETAIL
SET ACT_NAME = @ENTRY_NAME,
ACT_PRICE = @ENTRY_PRICE,
ACT_DESCRIPT = @ENTRY_DESCRIPT,
ACT_DOG_FRIENDLY = @PET_FRIENDLY,
ACT_AGE_RESTRICTION = @AGE_RESTRICTION,
ACT_PRICE_RANGE_ID = @PRICE_RANGE_ID
WHERE NOT EXISTS (SELECT 1 FROM dbo.[ACTIVITY_DETAIL] WHERE ACT_NAME = @ENTRY_NAME);
END
IF @ENTRY_TYPE = 'BUSINESS'
BEGIN
UPDATE BUSINESS_DETAIL
SET BUSINESS_NAME = @ENTRY_NAME,
BUSINESS_PRICE = @ENTRY_PRICE,
BUSINESS_DESCRIPT = @ENTRY_DESCRIPT,
BUSINESS_DOG_FRIENDLY = @PET_FRIENDLY,
BUSINESS_PRICE_RANGE_ID = @PRICE_RANGE_ID
WHERE NOT EXISTS (SELECT 1 FROM dbo.[BUSINESS_DETAIL] WHERE BUSINESS_NAME = @ENTRY_NAME);
END
IF @ENTRY_TYPE = 'HOTEL'
BEGIN
UPDATE HOTEL_DETAIL
SET HOTEL_NAME = @ENTRY_NAME,
HOTEL_PRICE = @ENTRY_PRICE,
HOTEL_DESCRIPT = @ENTRY_DESCRIPT,
HOTEL_PET_FRIENDLY = @PET_FRIENDLY,
HOTEL_PRICE_RANGE_ID = @PRICE_RANGE_ID
WHERE NOT EXISTS (SELECT 1 FROM dbo.[HOTEL_DETAIL] WHERE HOTEL_NAME = @ENTRY_NAME);
END
IF @ENTRY_TYPE = 'RESTAURANT'
BEGIN
UPDATE RESTAURANT_DETAIL
SET RESTAURANT_NAME = @ENTRY_NAME,
RESTAURANT_PRICE_AVG = @ENTRY_PRICE,
RESTAURANT_DESCRIPT = @ENTRY_DESCRIPT,
RESTAURANT_DOG_FRIENDLY = @PET_FRIENDLY,
RESTAURANT_PRICE_RANGE_ID = @PRICE_RANGE_ID
WHERE NOT EXISTS (SELECT 1 FROM dbo.[RESTAURANT_DETAIL] WHERE RESTAURANT_NAME = @ENTRY_NAME);
END
END
Solution 1:[1]
UPPER @ENTRY_TYPE NVARCHAR(20) = '',
UPPER @ENTRY_NAME NVARCHAR(50),
These are wrong. No such usage. @ENTRY_TYPE NVARCHAR(20) = '', @ENTRY_NAME NVARCHAR(50),
SELECT @ENTRY_TYPE = UPPER(@ENTRY_TYPE);
SELECT @ENTRY_NAME = UPPER(@ENTITY_NAME);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |