SQL Server Performance

need help with reusable code

Discussion in 'Getting Started' started by triviii, May 10, 2010.

  1. triviii New Member

    Hi guys, Please help me with this ASAP
    I got a code which is reused so many times in my query...it's a long code..i want to know wether i can set a name to that code and use that name instead of that code..i tried of using userdefined function but i couldnt get that as i'm not that much practised on that..
    so here is the code..

    (substring(stuff(column,CHARINDEX('.', column),CHARINDEX('',column,3)-CHARINDEX('.',column),''),0,charindex('',stuff(column,CHARINDEX('.', column),CHARINDEX('',column,3)-CHARINDEX('.',column),''),charindex('',stuff(column,CHARINDEX('.', column),CHARINDEX('',column,3)-CHARINDEX('.',column),''),charindex('',stuff(column,CHARINDEX('.', column),CHARINDEX('',column,3)-CHARINDEX('.',column),''),3)+1)+1)),column)

    i need to use the above code for so many times in my query
    the output of that code is a string..

    in breif the string will be like

    \tomkit.sun.ekabsfree og

    if i use the above code for this string i'll get the result as

    \tomkitabsfree

    in the above code colum=\tomkit.sun.ekabsfree og

    Thanq in advance
  2. FrankKalis Moderator

    Welcome to the forum!
    Is your question still current?
  3. Madhivanan Moderator

    Alternatively you can split a column value; remove string after dot and concatenate with

Share This Page