Author |
Topic |
ntn104
Posting Yak Master
175 Posts |
Posted - 2012-06-13 : 10:26:16
|
Hello,Please help me to write sql statement that I can split the field name into 3 different column: FISTNAME, LASTNAME, MIDDLENAMEFor example, Column "NAME" displayed as belowIGORIA MYKYTIUKANKUNJEANNNY C CLOUSEMIMMRAY KRAUSS &LONGER SR B LONGER CMARKET P JENHOPES COMICHALE R BROWNRICK J MANHEMThanks, |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-13 : 10:52:57
|
whats will be split up in case of MIMMRAY KRAUSS &?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-13 : 10:56:12
|
for others this would suffice based on sample data postedSELECT NAME,LEFT(NAME,CHARINDEX(' ',NAME + ' ')-1) AS FirstName,CASE WHEN LEN(NAME) - LEN(REPLACE(NAME,' ','')) > 1 THEN PARSENAME(REPLACE(NAME,' ','.'),2) ELSE NULL END AS MiddleName,CASE WHEN LEN(NAME) - LEN(REPLACE(NAME,' ','')) > 0 THEN PARSENAME(REPLACE(NAME,' ','.'),1) ELSE NULL END AS LastNameFROM Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2012-06-13 : 13:23:17
|
With this case, I think I will replace "&" for ''. Thanks,quote: Originally posted by visakh16 whats will be split up in case of MIMMRAY KRAUSS &?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2012-06-13 : 13:27:41
|
An error message for "parsename" not found. What function should we replace for that....I guess my sql not support that function.Thanks,quote: Originally posted by visakh16 for others this would suffice based on sample data postedSELECT NAME,LEFT(NAME,CHARINDEX(' ',NAME + ' ')-1) AS FirstName,CASE WHEN LEN(NAME) - LEN(REPLACE(NAME,' ','')) > 1 THEN PARSENAME(REPLACE(NAME,' ','.'),2) ELSE NULL END AS MiddleName,CASE WHEN LEN(NAME) - LEN(REPLACE(NAME,' ','')) > 0 THEN PARSENAME(REPLACE(NAME,' ','.'),1) ELSE NULL END AS LastNameFROM Table ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-13 : 15:32:51
|
are you not using MS SQL Server? if not, you may be better off posting this in relevant forum. This is MS SQL SErver forum and solutions given are sql server specific mostly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
ntn104
Posting Yak Master
175 Posts |
Posted - 2012-06-13 : 16:03:48
|
I do use MS SQL sever 6.5quote: Originally posted by visakh16 are you not using MS SQL Server? if not, you may be better off posting this in relevant forum. This is MS SQL SErver forum and solutions given are sql server specific mostly------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-13 : 16:32:26
|
oh...didnt realise you're still using such an old version. you should have posted it in correct forum then!------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|