Split FullName column

-- Create table dbo.FullNameTest
IF OBJECT_ID('FullNameTest') IS NOT NULL BEGIN
DROP TABLE dbo.FullNameTest;
END;
CREATE TABLE FullNameTest
(ID INT Not Null IDENTITY
, FullName NVARCHAR(80) Not Null
, CONSTRAINT PK_ID PRIMARY KEY CLUSTERED(ID)
GO
INSERT INTO FullNameTest
VALUES('Mr Hog Finn Gad'),('Grace Bruce'), ('Dr.Paul'), ('Master Clark James'), ('Mrs.Rignald')
SELECT * FROM FullNameTest
Rules
1. Treat entries
(Mrs,Mr,Miss
etc)
as
Titles
andi
gnore the dot (.) after
title
2.
When
we have title
and
a single name,
return
it
as
Title,
LastName
3.
When
we have title
andtwo
names return
it
as
Title,
FirstName
and
LastName
4.
When
we have title
and
three names,
return
Title,
FirstName
and
treat the rest
as
LastName
5.
When
we have
no
title,
reurn data
as
FirstName,L
astName
 6. No
function
required.
So we can get values like below:
Title FirstName LastName
Mr Hog Finn Gad
Null Grace Bruce
Dr Null Paul
Master Clark James
Mrs Null Rignald
Thank you
Zionlite

Splitting a string based on a delimiter has been discussed many times - searching the internet will find many examples and discussions. With a splitter function you can parse apart all of the individual elements - with the set of elements you can then apply
your logic. 
Next:
1. Treat entries
(Mrs,Mr,Miss etc) as Titles andi gnore the dot (.) after title
This is not a "rule".  You will need to identify the entire set of values you wish to consider titles.  "etc." is not something you can write logic with (nor test for).
Next:
6. No function required.
Perhaps you meant to say "cannot use a user-defined function"?  And in what context?  Is the use of a splitter function not possible?  Regardless, if you have very specific implementation requirements, you should identify the reason
behind them.  Given your level of experience, it may be that you have a fundamental misunderstanding or a false assumption.  Even if there are valid reasons for such, it is better to be aware of the implications of this path.
Next, your sample data should be concerning to you, since it is to me.  You have examples where there is no space between elements (e.g., Dr.Paul).  Perhaps there is an unspoken first cleansing step, which is to replace periods with a
single space?  In this case, part of rule 1 is incorrect since the period (if found) is significant and must be replaced with the appropriate delimiter (single space).    
Next, there are unspoken assumptions in your data and in your logic.  It appears that your data always comes in a specific order (though elements are optional).  Title, if provided, is first. The last element will always be the last name. 
There will always be at least 2 elements. And so forth. 
Lastly, this is logic that should be applied when the data is inserted or updated.  Do NOT expect to apply this on a query-by-query basis and expect efficient performance. 
I suggest you try developing your solution in a step-wise fashion.  First, go find a splitter function.  Then write a query that will apply this function to your string column.  Once you get that working, you can then start writing your logic. 

Similar Messages

  • Webi report display splits a column

    Hi
    fairly new to Webi so I hope this doesn't sound too basic. I have a Webi report that is 30 odd columns wide (this is currently BOXI R2 on Windows 2003); it's displayed in Landscape mode and splits several columns down the middle. How can you define where the vertical page breaks should be and/or which columns should not be split?
    Cheers
    Mark Gillis

    Thanks for getting back. That's not quite the problem: it's a 'standard' Webi report (not a crosstab) and has over 40 columns. Even in landscape mode, that displays over 5 pages. The problem is vertical splits: I can fit columns 1 to 7 on page 1 and then column 8 is half on the first page and half on the second (this is displaying in Page mode in Infoview: I can display in Draft mode, of course, to get a full span display of the report).
    What I'm trying to do is define the report so that when a user displays in Page mode columns do not get split. It may be that Draft mode is the only answer but I was hoping a setting would exist to say "don't split columns over pages".

  • Split a column based on even and odd rows

    Table1
          Table2
     Col1
    Odd
    Even
      A
     A
      B
      B
     C
      D
      C
     E
      F
      D
     G
      H
      E
     I
    NULL
      F
      G
      H
      I
    I am using MS SQL v2005
    I want to split a column into two columns : -
    one column must have all the odd rows data while the other column must have even rows data
    in other words I want the data in Table1 to be displayed as data in Table2. 
    Col, Odd and Even are column names

    In SQL 2005 wont approach like what I suggested do only a single scan of the table?
    A major problem with your solution is that you assume that 1) the values are contiguous 2) they are numeric. Try the below:
    CREATE TABLE #t (id INT NOT NULL IDENTITY(1,1), Col1 CHAR(1))
    INSERT INTO #t VALUES ('A'),('B'), ('C'),('D'), ('E'),('F'), ('G'), ('H'), ('I')
    go
    SELECT MAX(CASE WHEN Col1 % 2 > 0 THEN Col1 END),
    MAX(CASE WHEN Col1 % 2 = 0 THEN Col1 END)
    FROM
    SELECT Col1,ROW_NUMBER() OVER (PARTITION BY (Col1 % 2) ORDER BY Col1) AS Rn
    FROM #t
    )t
    GROUP BY Rn
    go
    ; WITH numbering AS (
        SELECT Col1, row_number() OVER (ORDER BY Col1) AS rowno
        FROM   #t
    ), leading AS (
       SELECT Col1 AS odd, LEAD(Col1) OVER(ORDER BY rowno) AS even, rowno
       FROM   numbering
    SELECT odd, even
    FROM   leading
    WHERE  rowno % 2 = 1
    go
    DROP TABLE #t
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to split a column in adobe livecycle design?

    How does one split a column in adobe livecycle design. I have found that one can split a column after you have merged it. But I want to split two columns into four in the middle of a table. This can be done in Word. Is there a way even if one has to split each row? Does any one know? Like in the table below I would like to make Header 2 & Header 3, Rows 2 and 3 into 2 rows 4 columns.
    Header 1
    Header 2
    Header 3
    Header 4
    Thanks
    Sheila

    If you want to have 1 column to be split in 4 columns, you can insert a table with 4 columns inside a column cell.. If you mean to add rows and you want to keep those 4 columns, you should add instances of the row where you inserted the table with 4 columns...
    Hope this helps!
    Mag

  • Split a Column to Three Columns

    Hello Y'all Gurus,
    I have a column and I need to split this column to three columns. The following are samples of data to be split:
    Sample #1: 
    From
    Column:  2.5 (3 - 47) or
                  2.5 (3-47) or
                  2.5(3 -47) or
                  2.5(3-41/47)
    To
    Column #1: 2.5
    Column #2: 3
    Column #3: 47
    Sample #2:
    From
    Column:  4X6(2-72)
    To
    Column #1: 4
    Column #2: 2
    Column #3: 72Any and all the help would be greatly appreciated.
    Thanks in advance.

    Hi,
    Try this. If there are any cases this may fail let me know. Not unit tested.
    SQL> WITH T
      2       AS (SELECT '2.5 (3 - 47)' TXT FROM DUAL
      3           UNION ALL
      4           SELECT '2.5 (3-47)'  FROM DUAL
      5           UNION ALL
      6           SELECT '2.5(3 -47)' FROM DUAL
      7           UNION ALL
      8           SELECT '2.5(3-41/47)' FROM DUAL
      9           UNION ALL
    10           SELECT '4X6(2-72)' FROM DUAL)
    11  SELECT REGEXP_SUBSTR (TXT, '^(\.[0-9]+|[0-9]+(\.[0-9]*)?)') COL1
    12        ,LTRIM (REGEXP_SUBSTR (TXT, '\((\.[0-9]+|[0-9]+(\.[0-9]*)?)'), '(') COL2
    13        ,RTRIM (REGEXP_SUBSTR (TXT, '(\.[0-9]+|[0-9]+(\.[0-9]*)?)\)'), ')') COL3
    14    FROM T;
    COL1         COL2         COL3
    2.5          3            47
    2.5          3            47
    2.5          3            47
    2.5          3            47
    4            2            72
    SQL> G.

  • Split multiple columns into rows using XML

    Hi Forum,
    I am trying to split 2 columns that each contain values separated by semicolon into single rows. The relation between the values of the two columns is that the order in the cells corresponds to each other.
    The data looks like this:
    pk    Manufacturer                partnumber
    1     Man1; Man2;Man3      PN1;PN2;PN3
    2     Man4; Man2;Man5      PN4;PN5;PN6
    The result should be:
    pk    Manufacturer     partnumber
    1       Man1                   PN1
    1       Man2                   PN2
    1       Man3                   PN3
    2       Man4                   PN4
    2       Man2                   PN5
    2       Man5                   PN6
    I am not sure how to format the XML to get a useful Basis for XML.value or XML.query
    Any ideas?
    TIA
    Alex

    Hi,
    Try like this ,
    DECLARE @tmp TABLE (pk INT,Manufacturer NVARCHAR(50),partnumber NVARCHAR(50))
    INSERT @tmp SELECT 1,'Man1; Man2;Man3','PN1;PN2;PN3'
    INSERT @tmp SELECT 2,'Man4; Man2;Man5','PN4;PN5;PN6'
    SELECT * FROM @tmp
    SELECT tmp2.pk pk,Manufacturer,partnumber FROM (
    SELECT ROW_NUMBER()OVER(ORDER BY tmp1.pk) RN,* FROM (
    SELECT pk,
    LTRIM(i.value('.','varchar(100)')) Manufacturer
    FROM ( SELECT pk, Manufacturer,
    CONVERT(XML,'<r><n>'
    + REPLACE(Manufacturer,';', '</n><n>') + '</n></r>') AS X
    FROM @Tmp) Spt
    CROSS APPLY Spt.X.nodes('//*[text()]') x(i)
    ) tmp1 ) tmp2
    JOIN
    (SELECT ROW_NUMBER()OVER(ORDER BY pk) RN,* FROM (
    SELECT pk,
    j.value('.','varchar(100)') partnumber
    FROM ( SELECT pk, partnumber,
    CONVERT(XML,'<r><n>'
    + REPLACE(partnumber,';', '</n><n>') + '</n></r>') AS Y
    FROM @Tmp) Spt
    CROSS APPLY Spt.Y.nodes('//*[text()]') y(j)) tmp2 ) tmp3 ON tmp3.RN = tmp2.RN
    sathya - www.allaboutmssql.com ** Mark as answered if my post solved your problem and Vote as helpful if my post was useful **.

  • Splitting one column into different columns.

    Hello Experts,
    How do i split datetime column into different columns while doing a Select statement.
    Ex:
    The column "REC_CRT_TS" has data like "2014-05-08 08:23:09.0000000".The datatype of this column is "DateTime". And i want it in SELECT statement like;
    SELECT
    YEAR(DATETIME) YEAR,
    MONTH(DATETIME) MONTH,
    DATENAME(DATETIME) MONTHNAME,
    DATEPART(DATETIME) WEEKNUM,
    DAY(DATETIME) DATE,
    DATEPART(DATETIME) HOUR
    FROM TABLE_NAME;
    The output should look like this;
    --YEAR| MONTH | MONTHNAME| WEEKNUM | DATE | HOUR
    --2014| 5 | May | 25 | 08 |08
    Any suggestions please.
    Thanks!
    Rahman

    I made a very quick research and I see in this blog post
    http://www.jamesserra.com/archive/2011/08/microsoft-sql-server-parallel-data-warehouse-pdw-explained/
    that  It also uses its own query engine and not all features of SQL
    Server are supported.  So, you might not be able to use all your DBA tricks.  And you wouldn’t want to build a solution against SQL Server and then just hope to upsize it to Parallel Data Warehouse Edition.
    So, it is quite possible that this function doesn't exist in PDW version of SQL
    Server. In this case you may want to implement case based month name or do it in the client application.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Splitting of column into furthur subcolumn's into an ALV list

    Hi All,
      I've to display the data in a alv grid in Such format.
    category
    name
    age
    |--|-|
    sc
    st
    As far as i know there is no way available  to split the column headinng furthur into subheadings.
      But any how if it is possible please tell me.
      Note : The above displayed list is just an eaxmple there may be dynamically furthur subdivision of it's heading.
    --Amit

    Amit,
    Its not possible to merge neither the headings nor the columns as such.
    Regards,
    Ravi

  • Splitting one column into 4 columns

    Hi,
      I want to split one column into 4 columns as shown below.
    parameters
    PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
    PanelPanel=MP12100173&YearYear=2013&Source=1&UserID=aac6440
    it should be display as 
    panel                      yearyear                source              userid
    MP01110201           2013                            1                    aad2779
    MP12100173           2013                            1                    aac6440
    there will be thousands of rows in the column. Can anybody help how to split it as shown.The length may very from row to row
    Thanks for your help.........
    BALUSUSRIHARSHA

    It is working...thank u very much... I found one more issue here
    PanelPanel=MP01110201&YearYear=2013&Source=1&UserID=aad2779
    PanelPanel=MP11100070&Source=1&PNR=2&YearYear=2014&UserID=ddc1535
    PanelPanel=MP11101276&Source=1&YearYear=2014&PNR=2&UserID=ddc1565
    I found 3 kinds of formats in the same column... I didn't observe the data carefully while posting the
    question..sorry about that. In this case if we need to show as
    panel                      yearyear                source
                 userid
    MP01110201           2013                            1                    aad2779
    MP11100070           2014                           1                    ddc1535
    MP11101276           2014                
              1                    ddc1565
    is it possible to filter like this? Should we use any case statement in query while we have diff formats
    like this?
    BALUSUSRIHARSHA

  • Avoid splitting of columns ALV report while download output to Excel sheet

    Hi friends,
                  I have 170 columns in my ALV report
    while downloading the report to Excel sheet
    the column descriptions and values are splitting in two lines.
    How can i avoid the problem.
    before calling REUSE_ALV_GRID_DISPLAY function module in my code
    for the Layout i assigned LS_LAYOUT-MAX_SIZE = 1023.
    but still the problem is not solved.
    Please help me in this Issue.
    Thanks in Advance,
    Ganesh

    Hi friends,
    I dont want to use and Keyboard shiftcntrl....
    or dont want to change any code in ALV report
    by simply assigning some value to any of the export parameter in ALV function module
    can we achieve the functionality
    Thanks in Advance,
    Ganesh

  • Split CLOB column to improve performance

    Hi All,
    We have a transactional table which has 3 columns and one among those is CLOB which holds XML data.Inserts are coming at 35K/hr to this table and data will be deleted as soon as job is completed. So anytime the total records in this table will be less than 1000.
    The XML data contains binary info of images and the size of each XML file ranges any where between 200KB to 600KB and the elapsed time for each insert varies from 1 to 2 secs depending upon the concurrency. As we need to achieve 125K/hour soon we were planning to do few modifications on table level.
    1. Increase the CHUNK size from 8KB to 32KB.
    2. Disabling logging for table,clob and index.
    3. Disable flashback for database.
    4. Move the table to a non default blocksize of 32KB. Default is 8KB
    5. Increase the SDU value.
    6. Split the XML data and store it on multiple CLOB columns.
    We don't do any update to this table. Its only INSERT,SELECT and DELETE operations.
    The major wait events I'm seeing during the insert is
    1. direct path read
    2. direct path write
    3. flashback logfile sync
    4. SQL*Net more data from client
    5. Buffer busy wait
    My doubt over here is ,
    1. If I allocate a 2G memory for the non default block size and change the clob to CACHE, will my other objects in buffer_cache gets affected or gets aged out fast?
    2. And moving this table to a SECUREFILE from BASICFILE will help?
    3. Splitting the XML data to insert into different columns in the same table will give a performance boost?
    Oracle EE 11.2.0.1,ASM
    Thanks,
    Arun

    Thanks to all for the replies
    @Sybrand
    Please answer first whether the column is stored in a separate lobsegment.
    No. Table,Index,LOB,LOB index uses the same TS. I missed adding this point( moving to separate TS) as part of table modifications.
    @Hemant
    There's a famous paper / blog post about CLOBs and Database Flashback. If I find it, I'll post the URL.
    Is this the one you are referring to
    http://laimisnd.wordpress.com/2011/03/25/lobs-and-flashback-database-performance/
    By moving the CLOB column to different block size , I will test the performance improvement it gives and will share the results.
    We dont need any data from this table. XML file contains details about finger prints and once the application server completes the job , XML data is deleted from this table.
    So no need of backup/recovery operations for this table. Client will be able to replay the transactions if any problem occurs.
    @Billy
    We are not performing XML parsing on DB side. Gets the XML data from client -> insert into table -> client selects from table -> Upon successful completion of the Job from client ,XML data gets deleted.
    Regarding binding of LOB from client side, will check on that side also to reduce round trips.
    By changing the blocksize, I can keep db_32K_cache_size=2G and keep this table in CACHE. If I directly put my table to CACHE, it will age out all other operation from buffer which makes things worse for us.
    This insert is part of transaction( Registration of a finger print) and this is the only statement taking time as of now compared to other statements in the transaction.
    Thanks,
    Arun

  • Batch Query with Batch but need address lines split by column

    Hi folks,
    I have the following query I created with the batch number of the sales order:
    SELECT T0.[DocDate] as "Date", T1.[DocNum] as "Sales Order Number",  T0.[CardCode] as "Customer Code", T0.[CardName] as "Customer Name",T1.[Address2], T0.[ItemCode],  T0.[ItemName], T0.[BatchNum], T0.[Quantity], T1.pickrmrk FROM IBT1 T0, ORDR T1 WHERE T0.[BaseNum] = T1.[DocNum] and T1.docstatus = 'O' and T0.WHSCODE = '01' order by T0.BaseNum
    Now I need to split the address by column so need street, block, city, county, country and zipcode fields from CRD1, but would either need the ship to address of the sales order it is selected or even just the default ship to address of the sales order.  In above query T1.[Adress2] is not quite right for our needs, as this file will have to be exported to 3rd party.  So I have gotten this far:
    SELECT T0.[DocDate] as "Date", T1.[DocNum] as "Sales Order Number",  T0.[CardCode] as "Customer Code", T0.[CardName] as "Customer Name",T1.[Address2], T2.[Street], T2.[Street], T2.[Block], T2.[City], T2.[County], T2.[Country], T2.[Zipcode], T0.[ItemCode],  T0.[ItemName], T0.[BatchNum], T0.[Quantity], T1.pickrmrk FROM IBT1 T0, ORDR T1, CRD1 T2 WHERE T0.[BaseNum] = T1.[DocNum] and T1.docstatus = 'O' and T0.WHSCODE = '01' and T0.[CardCode] = T2.[CardCode] and T2.[AdresType] = 'S' order by T0.BaseNum
    but will split into multiples if a business partner have more than one shipping address.
    Can someone please advise on this one?
    Many thanks in advance,

    Thanks Agustin, tried it with RDR12 as the following query:
    SELECT T0.[DocDate] as "Date", T1.[DocNum] as "Sales Order Number",  T0.[CardCode] as "Customer Code", T0.[CardName] as "Customer Name",T1.[Address2], T2.[StreetS], T2.[BlockS], T2.[CityS], T2.[ZipCodeS], T2.[CountyS], T2.[CountryS], T2.[ZipCodeS], T0.[ItemCode],  T0.[ItemName], T0.[BatchNum], T0.[Quantity], T1.pickrmrk FROM IBT1 T0, ORDR T1, RDR12 T2 WHERE T0.[BaseNum] = T1.[DocNum] and T1.docstatus = 'O' and T0.WHSCODE = '01' order by T0.BaseNum
    but has multiple lines for different addresses (and not just shipping addresses of that businss partner sales order).
    Anymore ideas or can you spot error in the query?
    Thanks again,

  • Splitting of Columns in report

    Hi Guys,
       Can some please help me with the following requirement. I have a report built on a multiprovider which brings 3 key figures from 3 different cubes. I have a user entry variable (CALMONTH1) which is used to restrict 2 of the key figures and a customer exit variable (CALMONTH2) which looks upong the value of CALMONTH1 value entered by the user and uses the same value to restrict the third key figure.
       CALMONTH1 can be entered as multiple months or range (say July to Sept). In the above mentioned scenario, the report is summing up the results for multiple months and showing the aggregated value (as expected). But the user wants to know if there is a way to split the results into multiple columns based on month. To be clear...if the user enters CALMONTH1 as July - Aug, then the layout of the report should be
         July                     
    KF1   KF2  KF3 
    SUM1  SUM2 SUM3               
        AUG        (as the next column to KF3 of July)
    KF1   KF2  KF3 
    SUM1  SUM2 SUM3   
         so that he can compare the values for different months. Please let me know if this functionality can be achieved without any additional inputs from the user. Any reply is highly appreciated and duely rewarded.

    Hi,
    You can try the following:
    Place 0CALMONTH into free chars area (aggregated accross months values) and applying drill down by it (indvidual months results).
    Best regards,
    Eugene

  • Splitting (2 columns) footer

    I have this text imported from word with footnotes and i want to use the CS5 split column function on the footers but it doesnt work. The footers are with in the rest of the text frame.
    Please help

    there you go

  • SQL Update to split 1 column into 2

    I have a column in a table that holds both a city and a zip ex. Jackson 44319
    I am trying to write an sql update query so that the 2 pieces of info would be split and funneled into their own respective column. For example:
    Before
    column name: address
    Jackson 44319
    After
    column name:city                             column name: zip
    Jackson                                           44319
    Here is what I have come up with so far, but it does not work correctly.
    Update Table
    Set city=Parsename(Replace(address ,',','.'),2),
    zip=Parsename(Replace(address ,',','.'),1)
    this query basically copies all my info from the address table and puts it into the zip table, and the city table remains null. yet, nothing gets split.

    Does your db have a bulk loading utility?  Do you have access to text manipulation tools such as awk?
    If so, using them is probably a better idea than using ColdFusion.

Maybe you are looking for

  • Payment method

    my payment method was declined. but i paid it already. any baody can tell me what is the problem pls. i want to use my account already and one thing more i cant update my all app. i downloaded

  • Moving to a new laptop - how to move my itunes

    I just got a new laptop.  How do I move my library of songs, playlists, etc from my old one to a new laptop?

  • Exceptions in Workbook?

    Hello All, I was informed that there is no possibility to create or edit exception in BEx Analyzer. So, I created exceptions from Query Designer. I would like to know if I can activate/deactivate these exceptions in BEx Analyzer. Regards, Mohana

  • 2 up postcard w/ data merge

    I can't figure this out. I want to create a double sided 8.5 x 11 sheet that has two 5.5 x 8.5 postcards on it. One side would be the front of the card (same image / no data merge) and the second side I' be data merging the mailing address. I have no

  • Once in the Mail app and have opened and email, what do the icons mean?

    I am able to open an email on my iPod touch but I do not know what the 5 icons at the bottom of the screen do. I know one is to reply, and one is to create a new message but that's it. Can anybody help me? Especially about the middle icon which looks