There are a number of things you can do in order to effect a simple string replacement;, however, I strongly suggest that you look into parameterization, to provide both injection safety and query-plan re-use.
Parameters also benefit by avoiding the quote issue - so just replace 'default'
with (for example) @p1
and you're sorted. This replace can be:
-- TSQL
REPLACE(@cmd, '''default''', '@p1')
or
// C#
.Replace(@"'default'", @"@p1")
From C#, this would a DbCommand
with parameters; from T-SQL you might consider sp_ExecuteSQL
. Either way, you'd want to end up with:
select * from tblname where test = @p1
And supply @p1 as the parameter. So from C#:
DbParameter param = cmd.CreateParameter();
param.Value = 0; // etc
cmd.Parameters.Add(param);
Or from TSQL:
EXEC sp_ExecuteSQL @cmd, N'@p1 varchar(50)', 0
(replace varchar(50)
with the correct type)