| 1 | -- ================================================
|
|---|
| 2 | -- Template generated from Template Explorer using:
|
|---|
| 3 | -- Create Procedure (New Menu).SQL
|
|---|
| 4 | --
|
|---|
| 5 | -- Use the Specify Values for Template Parameters
|
|---|
| 6 | -- command (Ctrl-Shift-M) to fill in the parameter
|
|---|
| 7 | -- values below.
|
|---|
| 8 | --
|
|---|
| 9 | -- This block of comments will not be included in
|
|---|
| 10 | -- the definition of the procedure.
|
|---|
| 11 | -- ================================================
|
|---|
| 12 | SET ANSI_NULLS ON
|
|---|
| 13 | GO
|
|---|
| 14 | SET QUOTED_IDENTIFIER ON
|
|---|
| 15 | GO
|
|---|
| 16 | -- =============================================
|
|---|
| 17 | -- Author: <Author,,Name>
|
|---|
| 18 | -- Create date: <Create Date,,>
|
|---|
| 19 | -- Description: <Description,,>
|
|---|
| 20 | -- =============================================
|
|---|
| 21 | CREATE PROCEDURE sp_GetClientsWithNoContact
|
|---|
| 22 | -- Add the parameters for the stored procedure here
|
|---|
| 23 | @agencyId int,
|
|---|
| 24 | @numberOfDaysStart int,
|
|---|
| 25 | @numberOfDaysEnd int
|
|---|
| 26 | AS
|
|---|
| 27 | BEGIN
|
|---|
| 28 | -- SET NOCOUNT ON added to prevent extra result sets from
|
|---|
| 29 | -- interfering with SELECT statements.
|
|---|
| 30 | SET NOCOUNT ON;
|
|---|
| 31 |
|
|---|
| 32 | select top 2000 K.* from KLIENCI K
|
|---|
| 33 | left join dbo.KONTAKTY K2 on K.CustomerId = K2.CustomerID
|
|---|
| 34 | left join dbo.AGENCI A on K.UserName = A.Symbol
|
|---|
| 35 | group by K.NameInMagazine, K.AgentExpo, K.kodKlienta, K.CustomerID, K.FirstName, K.LastName, K.OrganizationName,
|
|---|
| 36 | K.Address, K.City, K.State, K.PostalCode, K.Country, K.Nip, K.ContactName, K.PhoneNumber, K.FaxNumber,
|
|---|
| 37 | K.Note, K.data, K.Adres_Fkatura, K.Adres_Kor, K.Platnik_VAT, K.Aktywny,
|
|---|
| 38 | K.Email, K.UserName, K.Last_Modify, K.Modify_User, K.http, K.VIES, K.regon, K.krs, K.osw_nr,K.osw_wazne_do,K.Old_ID, K.NipKraj, A.Id_agencji
|
|---|
| 39 | HAVING datediff(day,max(K2.data),getdate()) > @numberOfDaysStart AND datediff(day,max(K2.data),getdate()) < @numberOfDaysEnd
|
|---|
| 40 | AND A.Id_agencji = @agencyId order by datediff(day,max(K2.data),getdate()) desc
|
|---|
| 41 |
|
|---|
| 42 | END
|
|---|
| 43 | GO
|
|---|