I am trying to search a text field for the words 'Ship complete' when I find this information I want it to put 'SC' into the output, if it doesn't find these words I want the output field to be blank. It is probably something I am doing wrong with the code but I can't seem to see it. Here is the code below and below that is the error message that I am getting.
Select SD.Sales_Order As [SO #],SD.SO_Line As [Ln]
,Cast(Min(SD.Status) As Varchar(1)) As [SS] ---Ln Status
,MIN(SH.Sales_Rep)As [Rep]
,MIN(SH.Customer)As [Cust ID]
,Min(SD.Material)As [Part Number]
,Min(M.Description)As [Description]
,Cast(Min(Case when SH.Note_Text like '%Ship complete%' then 'SC' As Varchar(2)) else '' end) [SC]
,Min(ISNULL(SD.Job,''))As [Linked]
,MIN(ISNULL(SD.PO,'')) As [PO] ---- Linked PO
,Cast(MIN(J.Status)As Varchar(1))As [St] ---- Job Status
,Cast(SUM((SD.Order_Qty - SD.Shipped_Qty) * (100 - SD.Discount_Pct) * SD.Unit_Price / 100) As Decimal(6,2)) As [Ext Amt]
,Min(SD.Order_Qty)As [Ord]
,Min(SD.Picked_Qty)As [Pick]
,MIN(SD.Backorder_Qty)As [BO]
,Min(SH.Order_Date)As [Ord Date]
,Min(M.Lead_Days)As [LD]
,Min(SD.Promised_Date)As [Promised]
from [PRODUCTION].dbo.SO_Detail As SD
INNER JOIN [PRODUCTION].dbo.SO_Header As SH
on SD.Sales_Order = SH.Sales_Order
and(SD.Status = 'Open' or SD.Status = 'Backorder'
or SD.Status = 'Hold' )
INNER JOIN [PRODUCTION].dbo.Material As M
on SD.Material = M.Material
LEFT OUTER JOIN [PRODUCTION].dbo.Job As J
On SD.Job = J.Job
Group by SD.Promised_Date, SD.Sales_Order, SD.SO_Line
Order by SD.Promised_Date, SD.Sales_Order, SD.SO_Line
Error message
Msg 156, Level 15, State 1, Line 8
Incorrect syntax near the keyword 'As'.
SWProduction