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
 Reverse Customer Name

Author  Topic 

figmo
Starting Member

18 Posts

Posted - 2011-04-26 : 17:59:18
SS08: Table has a customer name column that holds names like "Smith, John R" (Last, First, MI). Approx 60k records in the table

99% of the time, this is fine. But there are one or two reports that requires the name to be reversed to "John R. Smith" e.g. mailing labels. Customer demands names be FIRST MI LAST for these.

I have developed a scalar-valued function that flips the name correctly using some CHARINDEX and SUBSTRING calls. It's not overly complicated (2 CHARINDEX and 2 SUBSTRING calls and 2 LTRIM/RTRIM).

When I use it my query times go from 2 secs to 19 secs. For this application - this is too slow. I understand that query time will increase and am willing to accept 5-8 secs. But almost 20 secs is not acceptable to the customer.

Does anybody have any suggestions of a way to improve query times when calling a custom function such as this?

Or is there a way I can do it straight from the query command without calling a custom function? (not sure if these are inherently slow or not)

I'm considering just adding another column for the reversed name but I don't want to find and change all the code that adds/edits data to ensure they also update this new column.

Ideas anyone?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-04-26 : 18:05:48
You should be able to use the code in your function in-line with your query, depending on how you wrote it. If you post the function code and an example query we can fine-tune it for you.

Can you redesign the table to separate firstname, lastname, and initial? It's much easier to combine them in a pattern than to parse or rearrange them.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-04-26 : 18:41:22
wait...are you trying to modify rows, or present rows to an interface.

Seems like a batch mailing process, in which case 20 sec may not be so bad

So, is it an interface or a batch?

So what are we doing here?

Even 2 seconds is to much for an interface...if it's not sub second, you lose



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-04-26 : 18:49:30
and what is SS08:

Is that a question number?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-26 : 21:47:33
SQL Server 2008 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2011-04-26 : 22:23:56
You should be able to get the parsing of the column to be very fast. If the format is always LAST, FIRST M - and you don't have other possibilities (e.g. suffix/prefix like JR, SR, DR, etc...) that need to be parsed out, then you could create a 2 or 3 computed columns (and persist them if needed).

Once you have the computed columns defined on the table, then you can easily access those columns for any reporting you need.

Jeff
Go to Top of Page
   

- Advertisement -