Attribute Value Has Quotes

I imported new constituents with a comma delimited value for their attribute and it put the value in quotes.

Does anyone have code that could share to strip the quotes from the attribute field?

  • You have a couple of options.

    1) you could use the substring function, use the length function - 1 to find the end.

    2)  either of the functions below could work.  You can put the double quote in single quotes.

    USE [impresario]
    GO

    /****** Object: UserDefinedFunction [dbo].[LF_STRIP_FORMATTING] Script Date: 10/10/2023 3:41:04 PM ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER OFF
    GO

    CREATE FUNCTION [dbo].[LF_STRIP_FORMATTING] (
    @StrIn NVARCHAR(1024)
    )
    RETURNS NVARCHAR(1024)
    AS

    /****************************************************************************************/
    /* LF_STRIP_FORMATTING */
    /* Created By: Katie Lachance */
    /* Date Created: March 5, 2007 */
    /* */
    /* Strips @StrIn of its formatting -- removes spaces and non-alphanumeric characters. */
    /****************************************************************************************/

    BEGIN

    DECLARE @StrOut NVARCHAR(1024)

    SET @StrOut =
    CASE
    WHEN @StrIn = '' THEN NULL
    ELSE RTRIM(@strIn)
    END

    SET @StrOut = REPLACE(@StrOut,' ','')
    SET @StrOut = REPLACE(@StrOut,'.','')
    SET @StrOut = REPLACE(@StrOut,'-','')
    SET @StrOut = REPLACE(@StrOut,'(','')
    SET @StrOut = REPLACE(@StrOut,')','')
    SET @StrOut = REPLACE(@StrOut,'[','')
    SET @StrOut = REPLACE(@StrOut,']','')
    SET @StrOut = REPLACE(@StrOut,',','')
    SET @StrOut = REPLACE(@StrOut,'/','')
    SET @StrOut = REPLACE(@StrOut,'\','')
    SET @StrOut = REPLACE(@StrOut,'#','')
    SET @StrOut = REPLACE(@StrOut,'''','')

    RETURN @StrOut

    END

    GO

    ALTER AUTHORIZATION ON [dbo].[LF_STRIP_FORMATTING] TO SCHEMA OWNER
    GO

    GRANT EXECUTE ON [dbo].[LF_STRIP_FORMATTING] TO [ImpUsers] AS [dbo]
    GO

    GRANT EXECUTE ON [dbo].[LF_STRIP_FORMATTING] TO [tessitura_app] AS [dbo]
    GO

    -----------------------------------------------------------------------------------

    USE [impresario]
    GO

    /****** Object: UserDefinedFunction [dbo].[FS_REPLACE_NON_ALPHANUMERICS] Script Date: 10/10/2023 3:46:04 PM ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    CREATE FUNCTION [dbo].[FS_REPLACE_NON_ALPHANUMERICS] (@in_string VARCHAR(4000), @replace_char VARCHAR(255))
    RETURNS VARCHAR(4000)
    WITH SCHEMABINDING
    AS

    /********************************************************************************
    New Procedure CWR 5/15/2013 to replace non-alphanumerics with a character
    Modified CWR 6/27/2013 #2394 to work with multiple consecutive non-alphanumeric characters

    declare @description varchar(30) = 'cont-dt'

    Select description = replace(replace(replace(@description, '-', '_'), ':', '_'), '&', '_')

    select description = dbo.FS_REPLACE_NON_ALPHANUMERICS(@description, '123')

    *********************************************************************************/
    BEGIN

    DECLARE @searchpat VARCHAR(4000) = '%[^' + @replace_char + ',0-9,A-Z,a-z]%'
    DECLARE @out_string VARCHAR(4000)
    IF @in_string IS NULL
    BEGIN
    SELECT @out_string = NULL
    RETURN @out_string
    END

    SET @out_string = @in_string

    WHILE PATINDEX(@searchpat, @out_string) > 0
    BEGIN
    SET @out_string = REPLACE(@out_string, SUBSTRING(@out_string,PATINDEX(@searchpat, @out_string),1),@replace_char)
    END

    RETURN @out_string
    END

    GO

    ALTER AUTHORIZATION ON [dbo].[FS_REPLACE_NON_ALPHANUMERICS] TO SCHEMA OWNER
    GO

    GRANT EXECUTE ON [dbo].[FS_REPLACE_NON_ALPHANUMERICS] TO [ImpUsers] AS [dbo]
    GO

    GRANT EXECUTE ON [dbo].[FS_REPLACE_NON_ALPHANUMERICS] TO [tessitura_app] AS [dbo]
    GO