Please look that alias name. I hope to set the value into a string var.
How to put single quote inside a string which is in single quote.
SET @SQLString = N'SELECT purDetQty as 'detQty',stkBatchCode as 'batchCode',purDetProductId as 'productId'
INTO #ProductTable FROM PurchaseDetail
INNER JOIN Stock on stkId=purDetStockId
WHERE purDetID=@detId'
You can put single quotes inside a string with single quotes in SQL by doubling them, i.e.:
Note that this is two single quotes (”), not one double quote (“)
However, in this case, you should not need to use the single quotes, but should be able to simply use