Dear All,
I have 2 queries as below which gives departments as 19864, 19871, 19888, 19889, 19893, 96442, 96473.
SELECT distinct TSF_TO_STRUCTURE FROM CTS_DOCUMENTS d INNER JOIN CTS_TRANSFERS t ON d.DOC_ID = t.DOC_ID WHERE (t.TSF_DUE_DATE < GETDATE()) AND (d.DOC_STATUS = 'New')
and another query for sending email to
SELECT d.DOC_ID, d.DOC_REFERENCE, d.DOC_SUBJECT, d.DOC_DATE1 as Doc_DueDate, t.TSF_FROM_STRUCT_STC_NAME as Doc_Sender,t.TSF_TO_STRUCT_STC_NAME as Doc_Receipints,
d.DOC_SEQUENCE, d.DOC_STATUS, t.TSF_DATE, t.TSF_DUE_DATE, d.DOC_SENDER_FULL_NAME, d.DOC_RECIPIENT_FULL_NAME, d.DOC_REGISTERBY_STRUCTURE_FULLNAME
FROM CTS_DOCUMENTS d INNER JOIN CTS_TRANSFERS t ON d.DOC_ID = t.DOC_ID WHERE (t.TSF_DUE_DATE < GETDATE()) AND (d.DOC_STATUS = 'New') and TSF_TO_STRUCTURE=19871 ORDER BY d.DOC_ID DESC
Output as
DOC_REFERENCE DOC_SUBJECT Doc_DueDate Doc_Sender Doc_Receipints
202200001 Test from Mir 2022-01-16 00:00:00.000 Chief Finance Officer Strategy And Insights
202200001 Test from Mir 2022-01-16 00:00:00.000 Chief Finance Officer Strategy And Insights
And want to add in excel with multiple sheets as I have done in one excel sheet it's working but not in excel sheets with departments
Sample code:
private void refreshExcelTable_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server =INTALIO-MIR;Database=CTS_GEA;UID=ES;Password=ES;");
SqlCommand cmd = new SqlCommand("SELECT CTS_DOCUMENTS.DOC_ID, CTS_DOCUMENTS.DOC_REFERENCE, CTS_DOCUMENTS.DOC_SUBJECT, CTS_DOCUMENTS.DOC_DATE1 as Doc_DueDate, " +
"CTS_TRANSFERS.TSF_FROM_STRUCT_STC_NAME as Doc_Sender, CTS_TRANSFERS.TSF_TO_STRUCT_STC_NAME as Doc_Receipints," +
"CTS_DOCUMENTS.DOC_SEQUENCE, CTS_DOCUMENTS.DOC_STATUS, CTS_TRANSFERS.TSF_DATE," +
"CTS_TRANSFERS.TSF_DUE_DATE, CTS_DOCUMENTS.DOC_SENDER_FULL_NAME, CTS_DOCUMENTS.DOC_RECIPIENT_FULL_NAME," +
"CTS_DOCUMENTS.DOC_REGISTERBY_STRUCTURE_FULLNAME " +
"FROM CTS_DOCUMENTS INNER JOIN " +
"CTS_TRANSFERS ON CTS_DOCUMENTS.DOC_ID = CTS_TRANSFERS.DOC_ID " +
"WHERE(CTS_DOCUMENTS.DOC_DATE1 < GETDATE()) AND(CTS_DOCUMENTS.DOC_STATUS = 'New') " +
"ORDER BY CTS_DOCUMENTS.DOC_ID DESC", con);
try
{
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
BindingSource bsource = new BindingSource();
bsource.DataSource = dt;
string folderPath = "C:/Data/";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
using (XLWorkbook wb = new XLWorkbook())
{
wb.Worksheets.Add(dt, "WeeklyCorrespondences");
wb.SaveAs(folderPath + "DueCorrespondences.xlsx");
}
con.Close();
string message = "Export to Excel done";
}
catch (Exception ex)
{
}
}
One excel with mulple sheets with different departments
Thanks in advance