You are right, this is caused by sqlcmd for which $ is a special character.
One solution to fix this would be to concatenate two strings:
INSERT INTO SomeTable (SomeTextCol) Values (N'$'+'(function(){});');
It is a little ugly, but it works. An alternative would be to use a different symbol for jQuery like its complete name:
INSERT INTO SomeTable (SomeTextCol) Values (N'jQuery(function(){});');
Or, if you have a lot of references to jQuery inside the function:
(function(JQ){
JQ(
function(){
//other references to JQ
}
);
}
)(jQuery);
This last solution has the added advantage that anyone defining $
or JQ
anywhere else on the page won't break your code, as "your" JQ
is defined in a closure visible only to your code.