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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:54:40+00:00 2026-06-04T07:54:40+00:00

I wrote some stored procedure to transfer 2 tables data to a new, merged

  • 0

I wrote some stored procedure to transfer 2 tables data to a new, merged table.

  • Table 1 -> OldUsers table
  • Table 2 -> Hunters Table
  • Table 3 -> Users table

Table structures:

CREATE TABLE [dbo].[Users]
(
    [uid] [int] IDENTITY(1,1) NOT NULL,
    [username] [varchar](50) NULL,
    [password] [varchar](50) NULL,
    [state] [int] NULL,
    [name] [varchar](50) NULL,
    [license] [varchar](50) NULL,
    [lansno] [varchar](50) NULL,
    [curcuit_no] [varchar](50) NULL,
    [communism] [varchar](100) NULL,
    [Olduid] [int] NULL,
    [Is_hunter] [bit] NULL,
    [free_text] [text] NULL,
    [country] [varchar](50) NULL,
    [curcuit] [varchar](50) NULL,
    [license_territory] [varchar](50) NULL,
    [forest] [varchar](50) NULL,
    [association] [varchar](50) NULL,
    [hunt_ar] [varchar](50) NULL,
    [area] [varchar](50) NULL,
    [contract] [varchar](50) NULL,
    [radio_frequency] [varchar](50) NULL,

    CONSTRAINT [PK_timeuser] 
        PRIMARY KEY CLUSTERED ([uid] ASC)
)

I wrote some stored procedure to import data. BUT when I normally execute then pass ALL NULLS (whole table filled with NULLS). After that I remove

Where @uid = @index;   

and then execute. Then I saw one id repeated everywhere.

ALTER PROCEDURE [dbo].[UserTransfer]
AS
    declare @OldUser_tbl_count int;
    declare @Hunters_tbl_count int;

    declare @index int;
    set @index = 1;

    declare @uid int;
    declare @usr varchar(50);
    declare @psw varchar(50);
    declare @stat int;
    declare @name varchar(50);
    declare @license varchar(50);
    declare @lansno varchar(50);
    declare @curcuit varchar(50);
    declare @commu varchar(100);
    declare @sid int;
    --declare @text text;
    declare @country varchar(50);
    declare @curc varchar(50);
    declare @terri varchar(50);
    declare @forest varchar(50);
    declare @assoc varchar(50);
    declare @hunt varchar(50);
    declare @area varchar(50); 
    declare @contract varchar(50);
    declare @radio varchar(50);
    declare @town varchar(100);
    declare @lans varchar(50);

    --SET @OldUser_tbl_count = (SELECT COUNT (*) from OldUsers)
    SELECT @OldUser_tbl_count = COUNT (*) from OldUsers;
    SELECT @Hunters_tbl_count = COUNT (*) from Hunters;

-- entering from OldUsers to Users tbl
while(@index <= @OldUser_tbl_count)
BEGIN
    Select @uid=OldUsers.uid , @usr=OldUsers.username , @psw=OldUsers.password , @stat=OldUsers.state,
@name = dbo.OldUsers.name, @license=OldUsers.license,@curcuit= OldUsers.curcuit_no,@commu= OldUsers.communism,@lans=OldUsers.lansno
FROM OldUsers 
Where @uid=@index;

INSERT INTO Users
Values (@usr,@psw,@stat,@name,@license,@lans,@curcuit,@commu,@uid,0,'','','','','','','','','','');

SET @index = @index+1;
END

-- entering from Hunters to Users tbl
While (@index <= @Hunters_tbl_count)
BEGIN
SELECT @uid=Hunters.id,@license=Hunters.licence,@name=Hunters.hunter,@country=Hunters.country,@curc=Hunters.circuit,
@terri=Hunters.licence_territory,@forest=Hunters.forest,@assoc=Hunters.association,@hunt=Hunters.hunt_ar,@area=Hunters.area,
@contract=Hunters.contract,@radio=Hunters.radio_frequency,@town=Hunters.town

From Hunters
Where @uid = @index;

INSERT INTO Users
VALUES      ('','','',@name,@license,'','',@town,@uid,1,'',@country,@curc,@terri,@forest,@assoc,@hunt,@area,@contract,@radio);

SET @index=@index+1;
END

-exec UserTransfer  
  • 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-04T07:54:42+00:00Added an answer on June 4, 2026 at 7:54 am

    Could you please try this two inserts?

    INSERT INTO Users
    Select username, [password], [state], name, license, lansno, curcuit_no, communism, [Uid], 0 ,'','','','','','','','','',''
    FROM OldUsers 
    
    INSERT INTO Users
    SELECT '', '', '', Hunter, licence, '', '', town, ID, 1, '', country, circuit, licence_territory, forest, association, hunt_ar, area, [contract], radio_frequency
    From Hunters
    

    Instead of selecting and inserting data record by record you can do it at once. Please check this link to Sql Server documentation.

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

Sidebar

Related Questions

I have one database. I executed a stored procedure on it. I wrote some
I am trying to write a stored procedure to decrypt some data encrypted by
I'm creating a stored procedure for searching some data in my database according to
I wrote some code (Java and LDAP) to create a user in the Active
In Sql Server 2005, I have a stored procedure, in which i have wrote
I am trying to write a simple Oracle Stored Procedure: CREATE OR REPLACE PROCEDURE
I have a data access layer which returns DataSets/DataTables by executing Stored Procedure. Everything
I wrote a stored procedure which returns contract status for anauthor. If author doesn't
I have a Entity Framework data mode that I insert to it some stored
I want to write a PLSQL stored procedure that accepts a table name as

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.