0

有人可以帮助我吗,我正在尝试为我想要的某些表设置记录总数的警报。在此示例中,我只是尝试返回 COUNT 作为其中一个表的结果,以说明有多少记录没有客户的时间表,但是除了所有这些例外情况之外 ,为通知创建查询

,我想不出我的情况的解决方案。

SELECT COUNT(A.CODREF)QTDEAGENDSEMAGENDA FROM REGISTROS A INNER JOIN ATENDENTES U ON U.CODUSUARIO = A.CODUSUARIO WHERE A.CODUSUARIO = 11 AND A.STATUS IS NULL AND A.CODREF NOT IN ( SELECT CODREF FROM RETORNOS WHERE CODDIALOGO IS NULL AND AGEND_INTERNO IS NULL ) AND DATEDIFF(DAY, A.INICIO, GETDATE())> 11

我要组装的所有查询在示例中都将如下所示。我曾想过创建一个视图。

调用我的观点:

SELECT QTDEAGENDSEMAGENDA FROM ALERTS

那么查询会很简单并且可以工作,但我看到它也在不使用的列表中。

这是我的代码,不适用于我设置的此查询或视图

 public class NotificationHub : Hub
{
    string qtdeAgendSemAgenda = string.Empty;

    [HubMethodName("sendNotifications")]
    public string SendNotifications()
    {
        using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
        {               

            string query = @"SELECT COUNT(A.CODREF)QTDEAGENDSEMAGENDA FROM REGISTROS A INNER JOIN ATENDENTES U ON U.CODUSUARIO = A.CODUSUARIO WHERE A.CODUSUARIO = 11 AND A.STATUS IS NULL AND A.CODREF NOT IN ( SELECT CODREF FROM RETORNOS WHERE CODDIALOGO IS NULL AND AGEND_INTERNO IS NULL ) AND DATEDIFF(DAY, A.INICIO, GETDATE())> 11";

            connection.Open();

            using (SqlCommand command = new SqlCommand(query, connection))
            {

                command.Notification = null;

                DataTable dt = new DataTable();

                SqlDependency dependency = new SqlDependency(command);

                dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                if (connection.State == ConnectionState.Closed)

                    connection.Open();

                var reader = command.ExecuteReader();

                dt.Load(reader);

                if (dt.Rows.Count > 0)
                {
                    qtdeAgendSemAgenda = (dt.Rows[0]["QTDEAGENDSEMAGENDA"].ToString());                        
                }

            }

        }

        IHubContext context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>();

        return Tratar.String(context.Clients.All.RecieveNotification(qtdeAgendSemAgenda));


    }
4

0 回答 0