• You can actually do like this just replace “,” with Single Quote & Comma & Single Quote will get you the answer. Along with that, we have to prepend “SELECT ” with a Single Quote and add a Single Quote at last.

    the final code looks something like this

    DECLARE @p NVARCHAR(MAX)

    SELECT @P = 'AFGSDFGSDF,BSDF,CSDF,D'

    DECLARE @STRSQL NVARCHAR(MAX)

    SET @STRSQL = 'SELECT ''' + REPLACE(@P,',',''',''') + ''''

    EXEC( @STRSQL)