Possible Duplicate:
Parameterizing a SQL IN clause?
Hi, I have a query looks like this:
SELECT
CompanyId
FROM
CompanyTable
WHERE
CompanyName IN ('Subway', 'A & W', 'Pizzahut')
Is there any way I can use sql parameters for the names list?
This is not a stored proc (which I prefer but can't use in this project). When I say 'parameter', I mean parameter in the parametrized inline sql.
I use MS Enterprise Library so my parametrized inline sql looks like this:
string sql = "SELECT * FROM Company WHERE CompanyID = @companyId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetSqlStringCommand(sql);
db.AddInParameter(dbCommand, "companyId", DbType.Int32, 123);
...
It is pretty straightforward for simple cases like above. But when it comes to something like
SELECT
CompanyId
FROM
CompanyTable
WHERE
CompanyName IN ('Subway','A & W','Pizzahut').
I have no idea how to use parameters here.