テーブルに入力された最近の月と年に応じてデータベースからレコードをフェッチします。レコードの月と年を表示するテーブルに列があります。月と年。以下は、使用したspですが、降順でレコードを取得するだけです。私は最近の月と年のすべてのレコードをデータベースからのみ取得します。入力された最近の月と年に応じてレコードを取得します
where [email protected]
and Month = Month(DateAdd(month, -1, getDate())) -- month for 1 month ago
and Year = Year(DateAdd(month, -1, getDate())) -- year for 1 month ago
が、良いことでは暦月を(なぜあなたは部品内の格納されているあなたのテーブルに計算列を追加するには、次のようになります。
ALTER PROCEDURE [dbo].[Proc_GetComplianceClientIDBy_ProfileID]
@ProfileID varchar(100)
AS
BEGIN
SET NOCOUNT ON;
--Client Wise for the Currenct Month
select * into #Client_Business_Mapping
from TLConnectMasterDB.dbo.Client_Business_Mapping with(nolock)
where [email protected]
select ClientID,CM_ClientName, SM.SM_Name as StateName,
LM.LM_Name as LocationName,CLM.CL_BranchName as BranchName,
ROUND(convert(float,sum(CompliedNo)*100/convert(float,
(sum(CompliedNo)+sum(NotCompliedNo)))),2) Compliance,
Round(convert(float,sum(NotCompliedNo)*100/convert(float,
(sum(CompliedNo)+sum(NotCompliedNo)))),2) NotCompliance
FROM RegulatoryDB..Monthly_Compliance_Summary MS WITH(NOLOCK)
join #Client_Business_Mapping
on CBM_Client_ID=ClientID collate database_default
join RegulatoryDB..Clients_Master CM with(nolock)
on CM_ClientID=CBM_Client_ID collate database_default
join RegulatoryDB..Client_LocationMaster CLM with(nolock)
on CLM.CL_ClientID = CM.CM_ClientID
and MS.State = CLM.CL_StateID
and MS.Location = CLM.CL_CityID
and MS.Branch=CLM.CL_BranchName
join RegulatoryDB..State_Master SM
on SM.SM_Code=CLM.CL_StateID
join RegulatoryDb..Location_Master LM
on SM.SM_Code=LM.SM_Code and LM.LM_Code=CLM.CL_CityID
where [email protected]
group by month, Year, ClientID, CM_ClientName, SM.SM_Name,
LM.LM_Name, CLM.CL_BranchName
Order by cast(Year as int) desc, cast(Month as int) desc
END
MySQLまたはSQL Serverを使用しているデータベースはどれですか? – Noob
SQL Serverを使用しています。 – Prakash
mysqlタグを使用しないでください。 – nacho