Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 spliting string of 2 columns in same table

Author  Topic 

abuzar
Starting Member

20 Posts

Posted - 2014-09-25 : 09:06:29
I have a table name tbl_testme with columns (id,mac,keys,outputmk)
mac column have 12 character and keys have 16 character
mac keys
6545da7n9hg8 hsi457s5sd77jk87

what i want is i need to split the column into 4 characters of both column
E.G

(6545 da7n 9hg8) and (hsi4 57s5 sd77 jk87)

after splitting i need to take last 4 character of key(jk87) and last 4 character of mac(9hg8)and join them and insert that into ouputmk column.

E.G.
(jk87-9hg8-sd77-da7n-57s5-6545-hsi4) i need this to insert in outputmk column

any help and explanation will be appreciated alot..:))

Arun Babu N
Starting Member

26 Posts

Posted - 2014-09-25 : 09:27:06
Select right('6545da7n9hg8',4)+ right('hsi457s5sd77jk87',4)

arunbabu
Go to Top of Page

abuzar
Starting Member

20 Posts

Posted - 2014-09-25 : 09:57:13
thanks for the reply dude but not the solution i needed..
hopefully i managed to get my output as i mentioned below i s the query.

select reverse
(
SUBSTRING(keys,13,4)+'-'+ (select SUBSTRING(mac,9,4))+'-'
+SUBSTRING(keys,9,4)+'-'+(select SUBSTRING(mac,5,4))+'-'
+SUBSTRING(keys,5,4)+'-'+(select SUBSTRING(mac,1,4))+'-'
+SUBSTRING(keys,1,4)
) as test from tbl_testme

can any help me writing a trigger to update the output i got in "test" to my column name (outputpk)
in my same table.
Go to Top of Page
   

- Advertisement -