"Evaluate" a string (assembled) that is returned from a table
I'm looking for a way to "evaluate" an assembled string that is stored in a table.
The table has string data with many types of special characters such as nchar(160) or nchar(8204). Many columns of it in many rows.
As a simple example let's take '>' + char(160) + '<' as the string data, and I want it to return "> <".
Looking for something that would be akin to SELECT EVALUATE_STRING(StringData) FROM Table.
DECLARE @TestTable TABLE(Seq INT IDENTITY, StringData nvarchar(100))INSERT INTO @TestTable VALUES ( '''>'' + char(160) + ''<''' ) --non-breaking spaceSELECT Seq, StringData FROM @TestTable--Shows the desired result when not selected from a tableSELECT '>' + char(160) + '<' AS 'Direct_Select__Desired_Results' --If I try a select statement, it doesn't work.SELECT Seq, (SELECT StringData) AS 'Subqueried_Data' FROM @TestTable--How do I get the desired results when selecting from a table? SELECT Seq, /*??*/ StringData AS '??Evaluated_StringData??' FROM @TestTable
Basically ''' will add 1 single quote ' into your string and hence you are getting the additional quotes..
Open in new window