本文介绍了sql查询将列的值添加到其他列.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有列
的表"ProductMaster"
产品代码
产品名称
ChapterCode
基本
CVD
SAD
密度
LCost
自定义


我的存储过程是..

I have table ''ProductMaster'' with columns

ProductCode
ProductName
ChapterCode
Basic
CVD
SAD
Density
LCost
Custom


My Stored procedure is..

Create PROCEDURE [dbo].[PROC_TransactionReport]
(@ProductName as varchar(50),@INR1 as money,@INR2 as money,@INR3 as money,@Dollarrate as money,
 @INR as money,@CustomINR as money,@Quantity as int,@StorageCost as money,@CLFLCharges as money,@LCINT as money,@HandlingLoss as money)
AS
BEGIN

SELECT ProductName,ChapterCode,(@Dollarrate*@INR) BASIC,
    (@Dollarrate*@CustomINR) CustomINR,
    ((@Dollarrate*@CustomINR) * DBO.DIVIDE(PM.LCost,100)) LCOST
FROM ProductMaster PM WITH(NOLOCK)  where Productname=@ProductName



现在,我想添加CustomINR和LCOST并在另一列的末尾显示"LCost",然后说"CustomINR + LCost" ...我该怎么做



Now i want to add CustomINR and LCOST and display in another column aftre ''LCost'' say ''CustomINR+LCost''...how can i do this

推荐答案

SELECT ProductName,ChapterCode,(@Dollarrate*@INR) BASIC,
    (@Dollarrate*@CustomINR) CustomINR,
    ((@Dollarrate*@CustomINR) * DBO.DIVIDE(PM.LCost,100)) LCOST,
    ((@Dollarrate*@CustomINR) + ((@Dollarrate*@CustomINR) * DBO.DIVIDE(PM.LCost,100)))  AS NewSumCustomINRandLCost
FROM ProductMaster PM WITH(NOLOCK)  where Productname=@ProductName



刚刚为所需的字段添加了另一个选择!



Just added another select for the field needed!


SELECT ProductName,ChapterCode,(@Dollarrate*@INR) BASIC,
    (@Dollarrate*@CustomINR) CustomINR,
    ((@Dollarrate*@CustomINR) * DBO.DIVIDE(PM.LCost,100)) LCOST,

((@Dollarrate*@CustomINR) + ((@Dollarrate*@CustomINR) * DBO.DIVIDE(PM.LCost,100))) as 'CustomINR plus LCost'

FROM ProductMaster PM WITH(NOLOCK)  where Productname=@ProductName



希望这会有所帮助:)

贾斯(Jas)



Hope this helps :)

Jas


这篇关于sql查询将列的值添加到其他列.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 21:00