• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1059
  • Last Modified:

How do I remove leading comma in SQL query results?

Hello. Below is my query from SQL query analyzer.

Question: How to rewrite to remove leading "," from query results? The current results are " , 234, 345" etc.

Thanks.

Declare @PacklistID varchar (15)
Declare @LineNum numeric
Declare @SerNumList varchar(1000)

SET @SerNumList = ''

select @PacklistID=PACKLIST_ID, @LineNum=LINE_NUM,@SerNumList = @SerNumList + ', ' + SERIAL_NUM
from APG_SN_DETAIL

insert into APG_SN_SUMMARY(PACKLIST_ID, LINE_NUM, SERIAL_LIST)VALUES(@PacklistID,@LineNum,@SerNumList)
0
D4430
Asked:
D4430
1 Solution
 
Scott PletcherSenior DBACommented:
Declare @SerNumList varchar(1000)

--remove the SET = ''

select @PacklistID=PACKLIST_ID, @LineNum=LINE_NUM,
    @SerNumList = ISNULL(@SerNumList + ', ', '') + SERIAL_NUM
from APG_SN_DETAIL
0
 
D4430Author Commented:
Thanks, that worked great.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now