I am trying to create a new view, but I also want this view to have a new column. The new column must be StkCode and Description_1 combined.
For example: If my StkCode is DX11122 and Description_1 is Vanilla Powder; I want a field that will read as follows: "Vanilla Powder - DX11122"
CREATE VIEW KFF_Rep_Comm
AS
SELECT vw_KLX_RepCommTrx.AccName AS AccountName
,vw_KLX_RepCommTrx.Account AS AccountNum
,vw_KLX_RepCommTrx.RepID
,vw_KLX_RepCommTrx.RepName
,vw_KLX_RepCommTrx.CommPerc AS CommPercent
,vw_KLX_RepCommTrx.Credit
,vw_KLX_RepCommTrx.Debit
,vw_KLX_RepCommTrx.MUPercent AS MarkUpPercent
,vw_KLX_RepCommTrx.ProfitPercent AS GrossProfitPercent
,vw_KLX_RepCommTrx.SgdTrxAmt AS InvValue
,vw_KLX_RepCommTrx.SgdCost AS Cost
,vw_KLX_RepCommTrx.SgdProfit AS GrossProfit
,vw_KLX_RepCommTrx.SgdQty AS QtySold_Kg
,vw_KLX_RepCommTrx.TxDate
,vw_KLX_RepCommTrx.TrCodeID
,vw_KLX_RepCommTrx.StkCode
,vw_KLX_RepCommTrx.RepCode
,vw_KLX_RepCommTrx.Reference
,Client.DCLink
,StkItem.StockLink
FROM Client
INNER JOIN vw_KLX_RepCommTrx
ON vw_KLX_RepCommTrx.AccName = Client.Name
INNER JOIN StkItem
ON StkItem.Code = vw_KLX_RepCommTrx.StkCode
ADD ItemAndCode VARCHAR
Update vw_KLX_RepCommTrx
SET ItemAndCode Concat(StkCode, ' - ',Description_1) ---HERE is where I am going wrong, I think?
答案 0 :(得分:6)
You simply need to add another column to your select:
CREATE VIEW KFF_Rep_Comm
AS
SELECT vw_KLX_RepCommTrx.AccName AS AccountName
,vw_KLX_RepCommTrx.Account AS AccountNum
,vw_KLX_RepCommTrx.RepID
,vw_KLX_RepCommTrx.RepName
,vw_KLX_RepCommTrx.CommPerc AS CommPercent
,vw_KLX_RepCommTrx.Credit
,vw_KLX_RepCommTrx.Debit
,vw_KLX_RepCommTrx.MUPercent AS MarkUpPercent
,vw_KLX_RepCommTrx.ProfitPercent AS GrossProfitPercent
,vw_KLX_RepCommTrx.SgdTrxAmt AS InvValue
,vw_KLX_RepCommTrx.SgdCost AS Cost
,vw_KLX_RepCommTrx.SgdProfit AS GrossProfit
,vw_KLX_RepCommTrx.SgdQty AS QtySold_Kg
,vw_KLX_RepCommTrx.TxDate
,vw_KLX_RepCommTrx.TrCodeID
,vw_KLX_RepCommTrx.StkCode
,vw_KLX_RepCommTrx.RepCode
,vw_KLX_RepCommTrx.Reference
,Client.DCLink
,StkItem.StockLink
,Concat(vw_KLX_RepCommTrx.StkCode, ' - ',vw_KLX_RepCommTrx.Description_1) as ItemAndCode
FROM Client
INNER JOIN vw_KLX_RepCommTrx
ON vw_KLX_RepCommTrx.AccName = Client.Name
INNER JOIN StkItem
ON StkItem.Code = vw_KLX_RepCommTrx.StkCode
It is not clear from your code where does column Description_1
come from, but I assume it is the same view vw_KLX_RepCommTrx
. If not - you can update it with the actual table/view name (or remove table/view name if column name is unique)