I am attempting to get the last word from table Project in SQL-Server 2017.
My code is as follows:
select
reverse(substring(reverse(ProjectDescription),1, charindex(' ', reverse(ProjectDescription)) -1)) as LastWord
from Project
Run Code Online (Sandbox Code Playgroud)
The code works if I ask isolate the table to a single line, but I need the last word for all lines in the field ProjectDescription.
当我运行上述代码时,出现以下错误:
传递给 LEFT 或 SUBSTRING 函数的长度参数无效。
请有人帮助我解决我哪里出错了。
我正在尝试创建一个新视图,但我也希望此视图有一个新列.新列必须是StkCode和Description_1的组合.
例如:如果我的StkCode是DX11122而Description_1是香草粉; 我想要一个字段如下:"香草粉 - 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 …Run Code Online (Sandbox Code Playgroud)