Code
create table ExampleTable
(
Name varchar(500)
CultureCode(5)
)
insert into ExampleTable values('Dit is een test', 'nl-NL')
insert into ExampleTable values('This is a test', 'en-GB')
insert into ExampleTable values('Ceci est un test', 'fr-FR')
insert into ExampleTable values('Dies ist ein Test', 'de-DE')
create procedure GetNameByCultures
(
@CultureCodes varchar(250)
)
as
begin
//Get ExampleTable items according to the culture codes stated in @CultureCodes
end
-Example:
CREATE TYPE StringListType AS TABLE
(
[str] varchar(5) NULL
)
I am using MS SQL 2012 V11.0.2100.60
Situation
I’m trying to find the best way (Performance wise) to extract the labels.
Methods I have thought of, but not yet tested are:
- Creating a user defined table type as shown in the above.
Upside: I know it has almost no performance on the database.
Downside: I have to add another parameter to the stored procedure.
- Creating a function which splits a string by the char: ‘,’
Downside: I know using “Right”, “Left”, “Like” and other varchar converting / editing properties are slow in SQL
UpSide: I can keep the processing in the database.
In the current situation i’m only sending one culturecode inside a user defined table type.
So it’s impossible to add the culturecode in this UDTT as you can’t add a UDTT to a UDTT.
My only option would be to add another parameter to the stored procedure which shouldn’t be to much of a issue… but we like to keep it to only one.
Does anyone happen to know another (better?) method or should I go with one of these?
Table valued parameters are the best way as you’re using 2008 onwards. (See MSDN).
I would thoroughly recommend you read SQL Server MVP Erland Sommarskog’s very comprehensive articles on the different methods available, with analysis and performance details.