Does anyone know what’s wrong with this code block.
CREATE FUNCTION [dbo].[udfGetPoint]
(
@UserID INT,
@SqlCountry VARCHAR(1000)
)
RETURNS INT
AS
BEGIN
DECLARE @Points INT
SET @Points = 1
DECLARE @RecordCount sysname
IF @SqlCountry <> ''
BEGIN
EXEC sp_executesql
N'SELECT @DynamicCount = COUNT(UserID) FROM Country WHERE UserID = '+@UserID+' AND LCValues IN (' + @SqlCountry + ')'
,N'@DynamicCount sysname OUTPUT'
,@RecordCount OUTPUT
IF @RecordCount > 0
SET @Points = @Points + 1
END
RETURN @Points
END
If i execute this i got following error:
Msg 102, Level 15, State 1, Procedure udfGetPoint, Line 15
Incorrect syntax near '+'.
You can’t concatenate in the parameter setting of a stored procedure.