Execute a sql string in sql server -
my code below, somehow there error near @name
declare @name nvarchar(max) = '(mm.dll, ben , jerry.exe)' declare @sql nvarchar(max)= 'select ordername, customer.version, count(distinct company.cid) counts [companydata] company inner join [vendor] mav on company.cid = mav.cid left outer join [customer] customer on company.vendorid = customer.vendorid , company.did = customer.did ordername in' + @name+ ' group customer.version, ordername' exec sp_executesql @sql
put single quote in declaration of @name
, remove hashes(#) in it:
declare @name nvarchar(max)='(''mm.dll'', ''ben , jerry.exe'')' declare @sql nvarchar(max)= 'select ordername, customer.version, count(distinct company.cid) counts [companydata] company inner join [vendor] mav on company.cid = mav.cid left outer join [customer] customer on company.vendorid = customer.vendorid , company.did = customer.did ordername in ' + @name+ ' group customer.version, ordername' exec sp_executesql @sql
Comments
Post a Comment