且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从这个SP获得多个价值

更新时间:2023-02-03 18:56:33

i做了一个单独的表,我用来过滤我的数据。然后我用我的表和连接创建了一个sp,这提高了我的查询执行速度和性能。
i made a separate table which i used to filter my data. And then i created a sp with my table and joins which has improved my query execution speed and performance.


任何proc都可以为你提供任意数量的值,你可以做多少选择如你所愿,proc可以返回多个表。您给了我们一个代码转储和一个模糊(易于实现)的要求。我不知道你在这里想要什么。
Any proc can give you as many values as you want, you can do as many selects as you want and a proc can return more than one table. You gave us a code dump and a vague ( and easy to fulfil ) requirement. I don''t see what you''re hoping for here.






我认为你需要添加根据您在select语句中的要求的where子句,即在
中添加where子句


Hi,

I think you need to add a where clause based upon your requirement in your select statement i.e add the where clause in

SELECT 
			AccountID,AccountName,CompanyName,OwnerTypeName,OwnerType,ContractID,UnitsPurchased,ContractStartDate,ContractEndDate
			,Email,SUM(AGG.BillableUsage) AS BillableUsage,
			(ltrim(str(100.0 * sum(AGG.BillableUsage) / agg.UnitsPurchased, 6, 2))) + '' %'' as Percenatge,
			(SUM(AGG.BillableUsage)/12) AS Average,
			CASE Agg.UnitsPurchased
			WHEN  ''100001'' THEN ''Y''  --((SUM(AGG.BillableUsage))> AGG.UnitsPurchased)
			ELSE ''N''
			END AS OverageYN,
			CASE agg.ContractEndDate
			WHEN agg.ContractEndDate THEN ''Y''
			ELSE ''N''
			END AS ExpectedToGoOveragebefore,
			CASE AGG.ContractEndDate
			WHEN AGG.UnitsPurchased THEN ''IN-OVERAGE''
			ELSE agg.ContractEndDate
			END AS ExpectedDate
 
	FROM   
			#AggrTransaction  AGG
	
	GROUP BY AGG.AccountID,AGG.AccountName,AGG.CompanyName,AGG.OwnerTypeName,AGG.OwnerType,AGG.ContractID,AGG.UnitsPurchased,AGG.ContractStartDate,AGG.ContractEndDate
			,AGG.Email,AGG.Percentage,AGG.Average,AGG.OverageYN,AGG.ExpectedToGoOveragebefore,AGG.ExpectedDate 		





这将解决您的问题。



或试试这个。





This will resolve your problem.

Or Try this.

SELECT TOP 1 
			AccountID,AccountName,CompanyName,OwnerTypeName,OwnerType,ContractID,UnitsPurchased,ContractStartDate,ContractEndDate
			,Email,SUM(AGG.BillableUsage) AS BillableUsage,
			(ltrim(str(100.0 * sum(AGG.BillableUsage) / agg.UnitsPurchased, 6, 2))) + '' %'' as Percenatge,
			(SUM(AGG.BillableUsage)/12) AS Average,
			CASE Agg.UnitsPurchased
			WHEN  ''100001'' THEN ''Y''  --((SUM(AGG.BillableUsage))> AGG.UnitsPurchased)
			ELSE ''N''
			END AS OverageYN,
			CASE agg.ContractEndDate
			WHEN agg.ContractEndDate THEN ''Y''
			ELSE ''N''
			END AS ExpectedToGoOveragebefore,
			CASE AGG.ContractEndDate
			WHEN AGG.UnitsPurchased THEN ''IN-OVERAGE''
			ELSE agg.ContractEndDate
			END AS ExpectedDate
 
	FROM   
			#AggrTransaction  AGG
	
	GROUP BY AGG.AccountID,AGG.AccountName,AGG.CompanyName,AGG.OwnerTypeName,AGG.OwnerType,AGG.ContractID,AGG.UnitsPurchased,AGG.ContractStartDate,AGG.ContractEndDate
			,AGG.Email,AGG.Percentage,AGG.Average,AGG.OverageYN,AGG.ExpectedToGoOveragebefore,AGG.ExpectedDate 		





并且也使用order by子句。



谢谢



And use order by clause too.

Thanks