I was trying to execute the below statement to escape single quotes (i.e. using two single quotes):
declare @year varchar(max)
set @year = \'111,11\';
exec (
Ok... you want to take this string:
SELECT * FROM SplitValues(@year , ',')
And make it a string like this:
'SELECT * FROM SplitValues('111,11' , '','')'
So, your final code would be:
declare @year varchar(max), @sql varchar(max)
set @year = '111,11';
set @sql = 'SELECT * FROM SplitValues(''' + @year + ''' , '''','''')'
select @sql
Actually, finally select you would use exec() instead. However you really should probably use sp_sqlexecute for stuff like this since you can use paramaterized queries.