本文介绍了如何从数据库中获取多个值以给出多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sql Server查询.................





Sql Server Query.................


Create proc [dbo].[Get_Headwise_STax]
(
@ProjectId int

)
as
SELECT     Tax_Code.TaxCode_Id, Tax_Code.TaxCode, Tax_Code.serviceTax, Tax_Head.TaxH_Id, Tax_Head.Type, Tax_Head.Project_Id
FROM         Tax_Head INNER JOIN
                      Tax_Code ON Tax_Head.TaxCode_Id = Tax_Code.TaxCode_Id INNER JOIN
                      TaxMst ON Tax_Head.Project_Id = TaxMst.Project_Id
WHERE     (Tax_Head.Project_Id = @ProjectId)





TaxCode_Id TaxCode serviceTax TaxH_Id Type Project_Id



11 002 4 10 U 44

10 001 3.75 11 P 44

10 001 3.75 12 O 44

10 001 3.75 13我44







想要输出...... ..



根据TaxH_Id(UPOI)

我们想要标签价值,





4至label1

3.75至label2

3.75至label3

3.75至label4



TaxCode_Id TaxCode serviceTax TaxH_Id Type Project_Id

11 002410U 44
10 0013.7511P 44
10 0013.7512O 44
10 0013.7513I 44



And Want the output........

according to TaxH_Id(U P O I)
we want the label value,


4 to label1
3.75 to label2
3.75 to label3
3.75 to label4

推荐答案

SELECT     Tax_Code.TaxCode_Id, Tax_Code.TaxCode, Tax_Code.serviceTax, Tax_Head.TaxH_Id, case Tax_Head.Type when Tax_Head.Type='U' then 'label1' when Tax_Head.Type='P' then 'label2' when Tax_Head.Type='O' then 'label3' when Tax_Head.Type='I' then 'label4' else '' end, Tax_Head.Project_Id
FROM         Tax_Head INNER JOIN
                      Tax_Code ON Tax_Head.TaxCode_Id = Tax_Code.TaxCode_Id INNER JOIN
                      TaxMst ON Tax_Head.Project_Id = TaxMst.Project_Id
WHERE     (Tax_Head.Project_Id = @ProjectId)


SELECT     Tax_Code.TaxCode_Id, Tax_Code.TaxCode, Tax_Code.serviceTax, Tax_Head.TaxH_Id,
case
when Tax_Head.Type='U' then 'label1'
when Tax_Head.Type='P' then 'label2'
when Tax_Head.Type='O' then 'label3'
when Tax_Head.Type='I' then 'label4'
else '' end as label,
Tax_Head.Project_Id
FROM         Tax_Head INNER JOIN
                      Tax_Code ON Tax_Head.TaxCode_Id = Tax_Code.TaxCode_Id INNER JOIN
                      TaxMst ON Tax_Head.Project_Id = TaxMst.Project_Id
WHERE     (Tax_Head.Project_Id = @ProjectId)





这是一个固定版本



This is a fixed version


这篇关于如何从数据库中获取多个值以给出多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 21:42