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 8410967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:19:04+00:00 2026-06-10T00:19:04+00:00

I have a query where a record gets added to the table channels. Each

  • 0

I have a query where a record gets added to the table channels. Each record there is then assigned a channelID which is the PK for the table, and auto increments. After a record is added to the channel table I want to insert strings associate with that record into another table called channel keywords. My problem is that I also need to pass in the channelID that created in the previous query as a parameter for the insert statement for the channelskeywords table, but I am not quite sure how to do this.

    IF @matchBy ='title'
    BEGIN
    insert into channels
    (userID,matchTitle,matchTitleAbstract, fromMyPage)
    values
    (@userID,1,0,@fromMyPage)


    END 

    IF @matchBy ='TitleAbstract'
    insert into channels
    (userID,matchTitle,matchTitleAbstract, fromMyPage)
    values
    (@userID,0,1,@fromMyPage)
    BEGIN

    IF (NULLIF(@keyword1, '')) IS NOT NULL
    insert into channelsKeywords
  • 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-10T00:19:06+00:00Added an answer on June 10, 2026 at 12:19 am

    Try something like this

    BEGIN
        -- be sure to declare this same scope as the one whol will be using the value
        DECLARE @CNT INT
    
        insert into channels (userID,matchTitle,matchTitleAbstract, fromMyPage)
        values (@userID,1,0,@fromMyPage)
    
        SET @CNT = Scope_Identity()  -- holds the value of the inserted ID
    
    END 
    

    Additional Information:

    • @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes. You need to be careful here, since it’s across scopes. You could get a value from a trigger, instead of your current statement.

    • SCOPE_IDENTITY returns the last identity value generated for any table in the current session and the current scope. Generally what you want to use.

    • IDENT_CURRENT returns the last identity value generated for a specific table in any session and any scope. This lets you specify which table you want the value from, in case the two above aren’t quite what you need (very rare).

    See also here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query that updates one record, and only one record. Is there
I have the following MQL query which successfully returns the record for William Shakespeare.
I have a large table (2,000,000 rows) and I'd like to print each record
I have a query that updates a boolean value for a given record, then
I have a data access page which gets all it's data from a query
I have a table which contains around 400 000 records and which gets called
i have a table which contains 10000 records, now i have added the field
I have the following MySQL query which gets all the bookings for an agent,
Using SQL Server 2005 I have a query that gets child records from bundles
Ok, I have a LinqToXml query that returns a single record (correct terminology?), however,

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.