Go4Expert

Go4Expert (http://www.go4expert.com/)
-   SQL Server (http://www.go4expert.com/forums/sql-server-forum/)
-   -   MSSQL Server 2005, Help with Query to transfer infomation from multiple DBs (http://www.go4expert.com/forums/mssql-server-2005-help-query-transfer-t10927/)

DavidMiller 30May2008 16:05

MSSQL Server 2005, Help with Query to transfer infomation from multiple DBs
 
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

sql-programs 20Nov2009 00:29

Re: MSSQL Server 2005, Help with Query to transfer infomation from multiple DBs
 
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')



All times are GMT +5.5. The time now is 20:24.