My code is as below, somehow there is always an error near @Name
DECLARE @Name nvarchar(MAX) = '(mm.dll, ben and jerry.exe)'
DECLARE @sql nvarchar(MAX)= 'SELECT OrderName,
customer.version,
count(DISTINCT company.CID) as Counts
FROM [CompanyData] company
INNER JOIN [vendor] mav on company.CID = mav.CID
LEFT OUTER JOIN [Customer] customer on company.VendorId = customer.VendorId AND company.DId = customer.DId
WHERE OrderName in' + @Name+ '
GROUP BY
customer.version, OrderName'
EXEC sp_executesql @sql
5条答案
按热度按时间bksxznpy1#
Put a single quote in your declaration of
@Name
and just remove the hashes(#) in it:bq3bfh9z2#
Please add double quotes in @Name variable like..
jmo0nnb33#
it would probably save you a lot of grief if you store your names into a table value;
kcugc4gi4#
EXEC(@sql) or EXEC sys.sp_executesql @sql
shstlldc5#
Please add double single qoute in the string @name .