Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 402099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:05:39+00:00 2026-05-12T17:05:39+00:00

I have the following script: SELECT left(SHI.FSOKEY, 6) AS [SoNo] , substring(SHI.FSOKEY, 7, 3)

  • 0

I have the following script:

SELECT left(SHI.FSOKEY, 6) AS [SoNo]
,      substring(SHI.FSOKEY, 7, 3) AS [So Item]
,      right(SHI.FSOKEY, 3) AS [So Rels]
,      QAL.FCLOT AS [LotSerial]

FROM shmast SHM
     INNER JOIN shitem SHI
     ON SHM.FSHIPNO = SHI.FSHIPNO
     INNER JOIN qalotc QAL
     ON SHM.FSHIPNO = Left(QAL.FCUSEINDOC, 6)
        AND substring(QAL.FCUSEINDOC, 7, 6) = SHI.FITEMNO

This produces output that looks like this:

SoNo      So Item  SoRels  LotSerial
123456      1      001     ABCD
123456      1      001     AMOH
123456      1      001     POWK
123456      1      001     IUIL
123456      1      002     ABCE

I want to group by SoNo, SoItem, SoRels and get a list of LotSerials for each. So, my output would look like this:

SoNo      So Item  SoRels  LotSerial
123456      1      001     ABCD, AMOH, POWK, IUIL
123456      1      002     ABCE

I need to do so that I can pull this information back into a main query based on the SoNo, SoItem, SoRels.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:05:39+00:00Added an answer on May 12, 2026 at 5:05 pm

    @cmsjr beat me to it with his answer which is just bout the same. I do build the string differently, and have a complete working example.

    try this:

    CREATE TABLE YourTable  (SoNo int, SoItem int, SoRels char(3),  LotSerial char(4))
    go
    INSERT INTO YourTable VALUES (123456,1,'001','ABCD')
    INSERT INTO YourTable VALUES (123456,1,'001','AMOH')
    INSERT INTO YourTable VALUES (123456,1,'001','POWK')
    INSERT INTO YourTable VALUES (123456,1,'001','IUIL')
    INSERT INTO YourTable VALUES (123456,1,'002','ABCE')
    go
    CREATE FUNCTION LotSerial_to_CVS(@SoNo int, @SoItem int, @SoRels char(3))
    RETURNS varchar(2000) AS
    BEGIN
        DECLARE @cvs varchar(2000)
        SELECT @cvs=ISNULL(@cvs+', ','')+LotSerial
            FROM YourTable
            WHERE SoNo=@SoNo AND SoItem=@SoItem AND SoRels=@SoRels
        RETURN @cvs
    END
    go
    
    SELECT
        SoNo, SoItem, SoRels, dbo.LotSerial_to_CVS(SoNo, SoItem, SoRels)
        FROM YourTable
            GROUP BY SoNo, SoItem, SoRels
    

    OUTPUT:

    SoNo        SoItem      SoRels 
    ----------- ----------- ------ -----------------------
    123456      1           001    ABCD, AMOH, POWK, IUIL
    123456      1           002    ABCE
    
    (2 row(s) affected)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script select c.id from .TBL_COUPONS. as c inner join .TBL_BUSINESS.
I have a following bash script: 1 #!/bin/bash 2 query='query= SELECT * WHERE {
i have the following script <select id=select1> <option value=1>1day</option> <option value=2>2day</option> <option value=3>3day</option> </select>
I have the following query: SELECT script FROM d_stages WHERE id IN (SELECT g.stage
I have a script of the following structure: SELECT SUM(CASE WHEN pf.info IS NOT
I have the following setup <form name=\mylimit\ style=\float:left\> <select name=\limiter\ onChange=\limit()\> <option selected=\selected\>&nbsp;</option>; ...
I have the following string expression in a PowerShell script: select count(*) cnt from
I have the following script currently, which gets the category IDs as arrays: $sql_select_categories
I have following script that executes all the .reg files in the current directory.
I have following small script to preview some text before submitting it to store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.