Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This function ought to give you what you need.</p> <pre><code>--Drop Function Dbo.Part Create Function Dbo.Part (@Value Varchar(8000) ,@Part Int ,@Sep Char(1)='-' )Returns Varchar(8000) As Begin Declare @Start Int Declare @Finish Int Set @Start=1 Set @Finish=CharIndex(@Sep,@Value,@Start) While (@Part&gt;1 And @Finish&gt;0)Begin Set @Start=@Finish+1 Set @Finish=CharIndex(@Sep,@Value,@Start) Set @Part=@Part-1 End If @Part&gt;1 Set @Start=Len(@Value)+1 -- Not found If @Finish=0 Set @Finish=Len(@Value)+1 -- Last token on line Return SubString(@Value,@Start,@Finish-@Start) End </code></pre> <p>Usage:</p> <pre><code>Select ID ,Dbo.Part(Name,1,Default)As Name ,Dbo.Part(Name,2,Default)As Name1 ,Dbo.Part(Name,3,Default)As Name2 From Dbo.Table1 </code></pre> <p>It's rather compute-intensive, so if Table1 is very long you ought to write the results to another table, which you could refresh from time to time (perhaps once a day, at night).</p> <p>Better yet, you could create a trigger, which automatically updates Table2 whenever a change is made to Table1. Assuming that column ID is primary key:</p> <pre><code>Create Table Dbo.Table2( ID Int Constraint PK_Table2 Primary Key, Name Varchar(8000), Name1 Varchar(8000), Name2 Varchar(8000)) Create Trigger Trigger_Table1 on Dbo.Table1 After Insert,Update,Delete As Begin If (Select Count(*)From Deleted)&gt;0 Delete From Dbo.Table2 Where ID=(Select ID From Deleted) If (Select Count(*)From Inserted)&gt;0 Insert Dbo.Table2(ID, Name, Name1, Name2) Select ID ,Dbo.Part(Name,1,Default) ,Dbo.Part(Name,2,Default) ,Dbo.Part(Name,3,Default) From Inserted End </code></pre> <p>Now, do your data manipulation (Insert, Update, Delete) on Table1, but do your Select statements on Table2 instead.</p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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