Hi,
I have a table "Loads" with data as below
LoadNum LoadDate FileName TableName ClientID
60 2010-11-18 den_pat.dat GreatWestDenverLoad 123
61 2010-11-18 stl_pat.dat GreatWestStLouisLoad 123
62 2010-11-18 fac_pat.dat GreatWestFacetsLoad 123
63 2010-11-18 GWHLMTELIG.csv GreatWestILWULoad 123
64 2011-01-11 den_pat.dat GreatWestDenverLoad 123
65 2011-01-11 fac_pat.dat GreatWestFacetsLoad 123
66 2011-01-11 GWHLMTELIG.csv GreatWestILWULoad 123
67 2011-01-11 stl_pat.dat GreatWestStLouisLoad 123
i have to access all the load numbers with the same date and move them to another table.
For eg: All the load Num's 60,61,62,63 should be my input parameters to a procedure which moves the data to respective four tables(GreatwestDeneverWork,GreatWestStLouisWork,GreatWestFacetsWork,GreatWestILWUWork) i.e, 60 to GreatwestDeneverWork etc.,
i tried first taking all the distinct dates and save it in a list.
Then taking the dates one by one and then accessing it in where condition along with the four LoadNum as below
List<String> readerDate = new List<String>();
string Clientid = "123";
SqlDataReader sqlrdr;
SqlConnection sqlcon = new SqlConnection(strEligibility);
SqlCommand strSqlcmd;
strsql = "select distinct CONVERT(VARCHAR(10),LoadDate,120) from T_EligLoads where ClientID='" + Clientid.ToString() + "'";
strSqlcmd = new SqlCommand(strsql, sqlcon);
sqlcon.Open();
sqlrdr = strSqlcmd.ExecuteReader();
if (sqlrdr.HasRows)
{
while (sqlrdr.Read())
{
readerDate.Add(sqlrdr.GetString(0));
}
}
sqlrdr.Close();
sqlcon.Close();
foreach (string Txt in readerDate)
{
strsql = "select LoadNum,LoadDate,TableName from T_EligLoads where ClientID='" + Clientid.ToString() + "' and LoadDate='" + DateTime.Parse(Txt) + "' ";
strSqlcmd = new SqlCommand(strsql, sqlcon);
sqlcon.Open();
sqlrdr = strSqlcmd.ExecuteReader();
if (sqlrdr.HasRows)
{
while (sqlrdr.Read())
{
}
}
}
Now in the second loop where i am reading the datareader i have to access all the 4 load numbers and table names which would be the result of the query and send them to the stored procedure as parameters.
EXEC usp_LoadGreatWestEligibility @LoadNum1,@LoadnUm2,@LoadNUm3,@LoadNum4
eg: EXEC usp_LoadGreatWestEligibility 60,61,62,63
Could anyone please help me how should i read them and immediately execute so that i can read the data present for all the dates