Note that there are some explanatory texts on larger screens.

plurals
  1. POCSV issues in SQL---need help
    primarykey
    data
    text
    <p>I have this Split function which i got it from some site, now my problem is I am having one table where I want to push in imagespath. For now user can pass two images but in future there might be rise in the number of images required so we have used comma separated column which is a bad practice but was required in this case. Now when retrieve this images I want to segregate those images based on their ids</p> <p>in database</p> <pre><code>1 abc.png,xyz.png 2 fgvm.png,ghy.jpg </code></pre> <p>like I want</p> <pre><code>Imagepath ID abc.png 1 xyz.png 1 fgvm.png 2 ghy.jpg 2 </code></pre> <p>Using in the split function I'm doing this </p> <pre><code> select * from dbo.split ((SELECT ImagePath FROM dbo.AdvtManagement(nolock)),',') </code></pre> <p>But this query would give me like this </p> <pre><code>id val 1 abc.png 2 xyz.png 3 fgvm.png 4 ghy.jpg </code></pre> <p>Can somebody help me with what I want?</p> <p>split code</p> <pre><code>SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER FUNCTION [dbo].[Split] (@String varchar(8000), @Delimiter char(1)) returns @temptable TABLE (items varchar(8000)) as begin declare @idx int declare @slice varchar(8000) select @idx = 1 if len(@String)&lt;1 or @String is null return while @idx!= 0 begin set @idx = charindex(@Delimiter,@String) if @idx!=0 set @slice = left(@String,@idx - 1) else set @slice = @String if(len(@slice)&gt;0) insert into @temptable(Items) values(@slice) set @String = right(@String,len(@String) - @idx) if len(@String) = 0 break end return end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload