Set @InsertStr = ' INSERT into [dbo]. [T_schoolpercentmonth] ([Schoolid],[monthofyear],[percentnum]) VALUES ("' +cast (@SchoolID as nvarchar) + ', ' +convert (char (7), GETDATE (), +) + ', ' +cast (@PercentNum as nvarchar) + ' )‘;
Quoted words multibyte a pair of single quotes. ' SELECT * from TB where col= ' + ' ABCD ' + ' and true ' character if it is a variable value, plus two pairs of single quotes. ' SELECT * from TB where col= ' + @colval + ' and true ' if the character is the end of the statement, add four single quotes. ' SELECT * from TB where col= ' [email protected]+ '] If the reference is a numeric value, just add a pair: ' select * from TB where col= ' + @intval + ' and true ' as If the value is quoted and ends with a statement, the following single quotation mark does not: ' SELECT * from TB where col= ' [email protected]
Insert 3 single quotes when a variable is a character type in an SQL statement