Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8833419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:46:30+00:00 2026-06-14T08:46:30+00:00

I have a table Items which should have a corresponding record in the table

  • 0

I have a table Items which should have a corresponding record in the table LanguageText. The ID (Identity) of LanguageText is registered in the Items.LanguageTextId field in my Items table.

What I want to accomplish is a merge between LanguageText and Items for all records with null in Items.LanguageTextId and insert the itemname / text of these Item records in LanguageText plus update the LanguageTextId with the ID value from the newly inserted LanguageText record (SCOPE_IDENTITY()?)

The insert works fine:

MERGE [dbo].[LanguageText] AS target
USING (SELECT [Items].* from [dbo].Items ) AS source 
ON (TARGET.Id = SOURCE.LanguageTextId) 
WHEN NOT MATCHED By Target THEN 
    INSERT   
       ([Text])
 VALUES
       (source.[ItemName]);

end

But I don’t know how to update my items.Languagetextid, can I do something with:
OUTPUT $action, INSERTED.ID ?
Or is there a better way to have this done??

Thanks in advance,

Mike

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:46:31+00:00Added an answer on June 14, 2026 at 8:46 am

    You can do this with a merge..output to a table variable followed by an update.

    SQL Fiddle

    MS SQL Server 2008 Schema Setup:

    create table Items
    (
      ItemsId int identity primary key,
      ItemName nvarchar(50) not null,
      ItemsLanguageTextId int null
    );
    
    create table ItemsLanguageText
    (
      ItemsLanguageTextId int identity primary key,
      Text nvarchar(50) not null
    );
    
    insert into Items values('Name 1', null);
    insert into Items values('Name 2', null);
    insert into Items values('Name 3', null);
    

    Query 1:

    declare @T table
    (
      ItemsId int,
      ItemsLanguageTextId int
    );
    
    merge ItemsLanguageText as T
    using (
            select ItemsId, ItemName
            from Items
            where ItemsLanguageTextId is null
          ) as S
    on 0 = 1
    when not matched then
      insert (Text) values (S.ItemName)
    output S.ItemsId, inserted.ItemsLanguageTextId
      into @T;
    
    update Items
    set ItemsLanguageTextId = T.ItemsLanguageTextId
    from @T as T
    where T.ItemsId = Items.ItemsId;
    

    Results:

    Query 2:

    select * from Items;
    

    Results:

    | ITEMSID | ITEMNAME | ITEMSLANGUAGETEXTID |
    --------------------------------------------
    |       1 |   Name 1 |                  13 |
    |       2 |   Name 2 |                  14 |
    |       3 |   Name 3 |                  15 |
    

    Query 3:

    select * from ItemsLanguageText;
    

    Results:

    | ITEMSLANGUAGETEXTID |   TEXT |
    --------------------------------
    |                  13 | Name 1 |
    |                  14 | Name 2 |
    |                  15 | Name 3 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table Transactions(store_id, item_id, price). I want to find store_id's which sell
I have a table of items, user should be able to choose some of
I have a table with items in it (id, name, etc) and I want
I have a database which has an orders table and inventory table. The order-items
I have a List<> of items which I want to display in a 3
I have a table which contains the items the users of my game owns.
I have a table with items in it and I want a way to
I have a table of items which I'm getting from a few different online
Situation Say I have the following: a table items a table lists to which
I have a table which keeps parent-child-relations between items. Those can be changed over

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.