I am trying to create stored procedure which will decide which language to use based on a parameter passed?
How can I do something like this ?
declare @en varchar(50) = 'en' declare @fi varchar(50) = 'fi' select * from [@en].[TestingLanguagesInNameSpacesDelMe] select * from [@fi].[TestingLanguagesInNameSpacesDelMe]
I would also advocate a single-table/language-segmented design where all the languages are stored in a single table with a language column.
Dynamic SQL may be potentially vulnerable to SQL injection. If the @LANG variable cannot be trusted (or if the schema and table need to be validated to be a valid combination), you can check it against sys.schemas using a technique like this:
Now you have the power and flexibility of dynamic sql, but it is not vulnerable to injection.