[Solved] Need query to start at the beginning of the month


You could calculate the 1st of the month using EOMONTH something like this

SELECT DISTINCT ATB.AcountCountDesc,TB.LastFirstName,N.EMAIL,TB.AccountNumber,TB.OpenShareCount,TB.MemberOpenDate,
        TB.OpenMemberCount,TB.OpenShareBalance,SH.ShareType,FORMAT(SH.ShareOpenDate,'MM/dd/yyyy') AS "ShareOpenDate",
        SH.ShareCreatedByUser,SH.ShareCreatedByUserName,SH.ShareBranchName,SH.ShareBranch,cast(month(SH.ShareOpenDate) 
        as varchar) + "https://stackoverflow.com/" + cast(year(SH.ShareOpenDate) as varchar)as 'Open Period', CONCAT(SH.ShareCreatedByUser,'-',SH.ShareCreatedByUserName)
        'Opened By'
FROM arcu.vwARCUOperationMemberTrialBalance as TB
     JOIN arcu.vwARCUOperationMemberAccountTrialBalance as ATB
                ON TB.MemberSuppID = ATB.MemberID
                and TB.ProcessDate = ATB.PDate
                and TB.MemberStatus = 0 -- Account count for open Members only
                and TB.AccountStatus <> 1
     JOIN arcu.vwARCUShare AS SH
                ON TB.ProcessDate = SH.ProcessDate
                AND TB.AccountNumber = SH.AccountNumber 
     JOIN NAME AS N ON TB.AccountNumber = N.PARENTACCOUNT
WHERE
    ATB.AcountCountDesc = 1 AND 
    TB.OpenShareCount >= 1 AND
    SH.ShareType="00" AND
    SH.ShareID  !='40' AND
    SH.ShareOpenDate >= (select dateadd(day, 1, dateadd(month, -1, eomonth(getdate()))))  AND
    TB.MemberOpenDate = SH.ShareOpenDate AND
    N.EMAIL <> '' AND
    N.EMAIL is not null
order by MemberOpenDate Desc;

8

solved Need query to start at the beginning of the month