I know there's many of the same subjected question here in SO, my question is if I want to delete say around 1K rows rather few, given a List<int>
of RecordID
, I could avoid using a DataTable
, and send the list translated into a statement:
string ParmRecordsToDelete_CsvWhereIN = "("
for(int CurIdx=0; CurIdx < RecIdsToDelete.Count; CurIdx++)
{
ParmRecordsToDelete_CsvWhereIN += RecIdsToDelete[CurIdx] + ", ";
//this method to create passed parameter
//logic to remove on last Coma on last Index..
//or use stringJoin and somehow remove the last coma
}
ParRecordsToDelete_CsvWhereIN +=")";
This will create something Like "('1','2','3'......)"
and then create a SqlCommand
to call a stored procedure:
Delete * From @TblName WHERE @ColName IN @RecordsToDeleteCsvWhereIN
Is this an efficient approach? Is there a limit to the length of single parameter? I guess it's the N/VARCHAR(MAX)
length.
I guess if it's not a kinda hackish solution it would not be limited with length...
What would be the best fast solution, or am I on the right track as it is?
Declare @SomeList varchar(8000) SET @SiteList = '1,2,3,4,5,6,7' SELECT * from tblSomeTable WHERE Some_KeyID IN (SELECT Item FROM fnParseInt(@SomeList,','))
Delete FROM TABLE not Delete * FROM
I would suggest you start reading some basic Sql Tutorialslist fn
?