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
 The best way to execute a sproc against a table

Author  Topic 

bschweitzer
Starting Member

7 Posts

Posted - 2009-03-09 : 15:46:45
I'm new to SQL Server and am trying to use the great name parser code I found in the script library. I can get it to work for a single name, but don't know how to use it against a table. When I use the code below, it only seems to return the result from the last entry in the original view. I read something about cursors and might be able to use that, but I got the impression that there was probably a more efficient way. Any suggestions would be appreciated. Thanks!

declare @MyName varchar(100)
declare @MyEmail varchar(100)
select @MyName = FullName from v_InputData
select @MyEmail = Email from v_InputData
declare @MyH varchar(100)
declare @MyF varchar(100)
declare @MyM varchar(100)
declare @MyL varchar(100)
declare @MyS varchar(100)
exec dbo.NameParser
@NameString = @MyName,
@Honorific = @MyH Output,
@FirstName = @MyF Output,
@MiddleName = @MyM Output,
@LastName = @MyL Output,
@Suffix = @MyS Output
select @MyName, @MyH, @MyF, @MyM, @MyL, @MyS, @MyEmail

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-03-09 : 16:25:38
Since the SP is designed to work on a single set of inputs I guess you have a few options:

1. loop through your table calling this SP (as is) once for each row
(slow to run but quick to implement)

2. convert the SP to a userDefined, table valued Function and JOIN it to your table
(most extensible but difficult to implement)

3. take the logic of the SP and incorporate it in a adhoc query including your table, substituting the parameters with your column names.
(fastest performing, difficult to implement, and not extensible)

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -