Hi ,
Try Doing Something like this ?
BEGIN
declare @SQL VARCHAR(MAX)
SET @SQL='Select [Hadith_Text]
,[Hadith_Urdu]
,[Hadith_English]
,[Chapter_English_Name]
,[Chapter_Urdu_Name]
,[Baab_English_Name]
,[Baab_Urdu_Name]
,[Baab_Id]
,[Hadith_Book_Number]
From Hadiths_old
--Where ID < 34192 '
IF @WhereClause<>''
SET @SQL=@SQL+' '+'Where ID < 34192 AND'+ @WhereClause + ' order by ID'
ELSE
SET @SQL=@SQL+' '+'Where ID < 34192 order by ID'
EXEC(@SQL)
And In Your C# Code , Optimize it little bit ... I think You can do something like the following ...
On Your Button Click...
StringBuilder BookSelection = new StringBuilder();
foreach (int item in checkedListBox1.CheckedIndices)
{
if (BookSelection.Length == 0)
BookSelection.Append("Hadith_Book_Number In (");
BookSelection.Append(" '");
BookSelection.Append((item+1).ToString());
BookSelection.Append("' ");
}
if (BookSelection.Length > 0)
BookSelection.Append(")");