How to Update table column values that include & within the syntax. RRS feed

  • Question

  • User1909155429 posted

    I want to update all the database table columns that have a & included.

    For example: change Fridges & Freezers to Fridges & Freezers

    main reason being my app substitutes & for & when inserting data, then problems occur while

    i query multiple tables on the key value that has been manually entered with just the & syntax.  

    Monday, April 13, 2015 8:07 AM

All replies

  • User61956409 posted

    Hi peterthegreat,

    Thanks for your post.

    sp_rename could help to change the name of a user-created object in the current database. The object can be a table, index, column, alias data type, or Microsoft .NET Framework common language runtime (CLR) user-defined type. You could refer to the following code to rename the column.

    EXEC sp_RENAME '[TableName]. OldColumnName' , ' NewColumnName', 'COLUMN' 

    Best Regards,

    Fei Han

    Monday, April 13, 2015 9:45 PM
  • User1909155429 posted

    That would add difficulties during query!

    I note that you can insert manually the & sign though the system automatically alters encodes the syntax. Which is what happen in my case and cause a disruption.

    I wonder if i should replace the encoded part with plain & in the string,  to facilitate correct function.

    Would this be a major security problem? 



    Tuesday, April 14, 2015 9:29 AM