boolean threeArgs = args.size() > 2;
Object pattern = args.get(0);
Object string = args.get(1);
Object start = threeArgs ? args.get(2) : null;
StringBuffer buf = new StringBuffer();
buf.append("charindex(").append( pattern ).append(", ");
if (threeArgs) buf.append( "right(");
buf.append( string );
if (threeArgs) buf.append( ", char_length(" ).append( string ).append(")-(").append( start ).append("-1))");
buf.append(')");
return buf.toString();