Click here to Skip to main content
15,076,991 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
my problem is this. I have a database, that is ready to support localization. All localizable data is kept in separate table for each entity.


Table "UserGroup" has the following columns: UserGroupID, CreatedOn, ModifiedOn and Version

Table "UserGroupTranslation" has the following columns: UserGroupID, LanguageID, Name, Description
(UserGroupID and LanguageID form the key)

There is obviously another table "Language" which stores only two-character tags for used locales.

So the question is this. I have CRUD stored procedures for all tables, but I would like to represent "UserGroup" and "UserGroupTranslation" tables as single entity to external systems. My idea is to use transactions in SP, that would properly handle relationship between the two tables. Selecting, deleting and updating is not the problem, but with inserting, well there I'm a little short with my SQL knowledge.
I want to make a stored procedure, that first inserts new row in "UserGroup" table and then uses newly inserted ID and ID's of all used languages to insert as many rows in "UserGroupTranslation" table as there are used languages.

I hope I've been clear enough.

Any help would be appreciated.

Greetings, Tine
Updated 9-Dec-09 23:08pm

Do the following thing in your stored procedure which insert data

step 1 : insert data in UserGroup
step 2 : get identity value of pke higest value like select @pkey=@@identity

step 3 : write select inset query like

insert into UserGroupTranslation
select @pkey,LanguageID,name,description from
Language where languageuse=1

hope with the above things work for you.
Thank you very much for your help. The solution you provided does exactly what I want.

The following is raw code snippet that does the trick, if anybody else is interested.

declare @name nvarchar(50)
declare @description nvarchar(500)
declare @id int

set @name = 'name'
set @description = 'description'

insert into UserGroup default values

set @id = SCOPE_IDENTITY()

insert into UserGroupTranslation select @id, Language.LanguageID, @name, @description from Language

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900