SQL - Function to return the holds on an order

This script can be easily modified to return 'sub items' like 'holds for an order' in a comma separated value.

If you need any help using it, open a thread and reference this one and we'll help.

                       

CREATE FUNCTION dbo.ddf_AllHoldsOnASOPDoc (@vchrSopnumber varchar(21), @intSoptype int)
  RETURNS VARCHAR(200)
  
--  select dbo.ddf_AllHoldsOnASOPDoc ('std00424130',2)
                  
      
  
  
AS
BEGIN
    DECLARE @vchrHolds AS VARCHAR(200)
      
    SET @vchrHolds = ''
      
    SELECT @vchrHolds = @vchrHolds + ',' + rtrim(left(prchldid,2))
        FROM sop10104 with (nolock)
        WHERE sopnumbe = @vchrSopnumber
            and soptype = @intSoptype
            and delete1 = 0
        order by prchldid
      
    RETURN STUFF(upper(@vchrHolds), 1, 1, '')
  
  
  
END
GO

 

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences