Hi,
I have the following in a stored procedure:
DECLARE @new_column_name varchar(9)
DECLARE @table_name varchar(16)
DECLARE @SQLString nvarchar(2000)
SET @new_column_name = N'name'
SET @table_name = N'tbl_test_table'
SET @SQLString = N'SELECT @CountOUT = COUNT(*) FROM [' + @table_name + '] WHERE [' + @new_column_name + '] = ''' + @description + ''''``
This works absolutely fine until @description has a single quote in it. In my C# I replace single quotes with two single quotes but this is still causing a problem when creating the above SQL string.
Any ideas how to fix this for:
SET @description = N'Adam''s Car'
The reason I am using dynamic SQL is because the 'name' column is temporary and only exists during the lifetime of the stored procedure.