我有一个表名 Tankdet
它有两列 TCO
以及 Tanks
.
以下是存储过程代码,用于返回租用、拥有和主要坦克的计数:
ALTER PROCEDURE [dbo].[sp_Dash_LeaseInformation]
AS
BEGIN
DECLARE @leased INT
DECLARE @owned INT
DECLARE @principal INT
SET NOCOUNT ON
SET @owned = (SELECT COUNT(*) FROM Tankdet WHERE ownleasetank='owned')
SET @leased = (SELECT COUNT(*) FROM Tankdet WHERE ownleasetank='leased')
SET @principal = (SELECT COUNT(*) FROM Tankdet WHERE ownleasetank='principle')
SELECT [Leased]=@leased,[Owned]=@owned,[Principal]=@principal
SET NOCOUNT OFF
END
这张table看起来像这样
它返回如下值:,
leased = 4,owned = 4,principle = 7
用于在我的前端显示坦克计数的值。
问题是在这里我显示了整个计数的原则坦克,并返回到我的前端。
现在我在获取 Principle Tank
分别计算 TCO
,我必须将其作为:
SELECT [Leased]=@leased, [Owned]=@owned, [vibe]=@vibe, [baru]=@baru,[sarath]=@sarath, [karthi]=@karthi, [nth...]=@nth.....
这个 nth
是因为tco值可能会在将来增加,并且 selected
值必须返回如下:
租用=4,拥有=4,振动=2,巴鲁=3,萨拉特=1,卡蒂=1,n=n。。。。。。,
1条答案
按热度按时间62lalag41#
表(和结果集)的列数固定,行数可变。所以干脆回去吧
每行返回一行
ownleasetank
值以及计数。