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

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -