I want to attach numeric value in dynamic query but I am an getting error:
Conversion failed when converting the varchar value ' + @psRegionCode + ' to data type smallint
My query is:
SET @psRegionCode = UPPER(LTRIM(RTRIM(@psRegionCode)))
IF (@psRegionCode <> 0)
BEGIN
SET @sSQLStr = @sSQLStr + ' ' + 'AND reg.region_cd = ''' + @psRegionCode + ''''
END
Things which I tried:
SET @psRegionCode = UPPER(LTRIM(RTRIM(@psRegionCode)))
IF (@psRegionCode <> 0)
BEGIN
SET @sSQLStr = @sSQLStr + ' ' +
'AND reg.region_cd = ' + cast(@psRegionCode as nvarchar(10) ''
END
Can somone please help me with this?
mysql,postgresql,sql-server,oracleordb2- or something else entirely.