1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

MSSQL Server 2005, Help with Query to transfer infomation from multiple DBs

Discussion in 'SQL Server' started by DavidMiller, May 30, 2008.

  1. DavidMiller

    DavidMiller New Member

    Joined:
    May 30, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    Select id from tbl_account in Game_User DB
    
    id is binary data
    
    
    USE Billing
    INSERT INTO tblUser (userId,cpId,userTypeId,userStatusId,gameServiceId) VALUES ('test','1','1','9','6') where userId = id from tbl_account
    
    and
    
    INSERT INTO tblUserInfo (userNumber,userId,cpId,userTypeId,userStatusId,gameServiceId) VALUES ('123','test','1','1','9','6') where userNumber = userNumber and userId = userId from tblUser
    Im new when it comes to making SQL queries, so i need help badly.

    Basically what i need the query to do is call from a DB "User" id where the id is in Binary data. from that i need it to insert into 2 other tables in the Billing DB.

    the UserId needs to be the same in all areas, and when it inserts into tblUserInfo it has to pull from userNumber from tblUser after the rows are entered so that the userNumber in tblUser and tblUserInfo are the same.

    Hopefully you can help. if any further information is needed please just ask and ill try to give as much as i know.

    Thanks

    David
     
  2. sql-programs

    sql-programs New Member

    Joined:
    Oct 21, 2009
    Messages:
    14
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software Developer
    Home Page:
    Use the following scripts,
    You didn't mention any condition to retrive "id" column from tbl_account table.If the condition is avialable then add it in where condtion.
    Code:
    declare @ID as binary
    declare @UserNumber as binary
    
    set @ID=(Select id from Game_User.dbo.tbl_account)
    
    INSERT INTO Billing.dbo.tblUser (userId,cpId,userTypeId,userStatusId,gameServiceId) 
    VALUES (@ID,'1','1','9','6') 
    
    set @UserNumber=(select scope_identity())
    
    INSERT INTO Billing.dbo.tblUserInfo 
    (userNumber,userId,cpId,userTypeId,userStatusId,gameServiceId) 
    VALUES (@UserNumber,@ID,'1','1','9','6') 
     

Share This Page