473,398 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Update WHERE checking with another database

Hi, I'm Spanish and little English, I will try to understand me best.

I am creating an online game based on xml, lua and SQL Server, I have a database named accountdb and other named gamedb.

within accountdb This table accounts and within gamedb This table characters... Ok

in accountdb.accounts field site_code INT
in gamedb.characters field online INT

I need an update site_code set all rows to 1 if online is 0

For example:
Expand|Select|Wrap|Line Numbers
  1. UPDATE accountdb.dbo.accounts SET site_code = 1 WHERE online = 0
  2.  
The script runs on gamedb...

If I could help I would appreciate forever.

Greetings.
Sep 11 '11 #1
6 1710
You could write a trigger that applies ON UPDATE:
http://msdn.microsoft.com/en-us/library/ms189799.aspx

Otherwise you may use your application code to execute both queries (SET online = 0 and the other one you've mentioned), but that's considered bad practice.
Sep 11 '11 #2
thank you very much for the quick response, but is somewhat more complicated...

I need to check if any of yours characters is online, if not any of his characters gamedb online, update accoundb.site_code to 1 :/
Sep 11 '11 #3
Thanks for the help, I resolved, I leave here the code if it helps someone

Expand|Select|Wrap|Line Numbers
  1. Declare @ID numeric
  2.       Select @ID = (SELECT COUNT ("ONLINE") AS ONLINE FROM RZ_CHARACTER WHERE ACCN_ID = @ACCN_ID AND ONLINE = 1)
  3.  
  4.       IF @ID = 0      
  5.     UPDATE RZ_ACCOUNTDB.dbo.RZ_ACCOUNT SET SITE_CODE=1 WHERE SITE_CODE='' AND ACCN_ID=@ACCN_ID;  
  6. Else
  7.     UPDATE RZ_ACCOUNTDB.dbo.RZ_ACCOUNT SET SITE_CODE='' WHERE SITE_CODE='1' AND ACCN_ID=@ACCN_ID;  
Sep 11 '11 #4
NeoPa
32,556 Expert Mod 16PB
How would that work (not fail)?

If [Site_Code] is numeric then setting it to '' will fail. If [Site_Code] is textual then setting it to 1 will fail. As you do both in the same SQL I would expect it to fail.
Sep 11 '11 #5
xD yes... any ideas? I'm just using google translator and how to describe exactly what I'm ...

http://www.foroz.org/foroz/viewtopic...=582945#582945
Sep 11 '11 #6
NeoPa
32,556 Expert Mod 16PB
I have really no idea how to respond to that. You say that works, then you clearly indicate you know that it doesn't. What is there that I can sensibly respond to :-S
Sep 11 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Keith Wilby | last post by:
A97. I want to be able to use code to open change the data type of a field in a table in another database - can this be done? Many thanks. Keith.
1
by: Primerov | last post by:
Why i cannot update from another form? I have an update function called UpdateData that works otherwise,but not from another form. Why is it so? I am trying to update tables from the form F1.There...
2
by: Prakash Wadhwani | last post by:
I have a database called "TEMP" On Opening the "TEMP" Database, I need to use VBA : a) to connect to another database called "PMF" b) the PMF database requires a password on opening called...
4
by: Roxie Aho | last post by:
I'm trying to update a SQL2000 database through a web form. Visual Basic.Net 2003,This is an abbreviated chunk of code. The primary key field in the table is HospitalProviderNumber. It is an...
3
by: Bob | last post by:
For maintenance reasons I would like to split my DB in an Frontend and a Backend. The frontend is an MDE. The backend contains all the tables. Nothing special. But I will also have my reports in...
6
by: Ted | last post by:
I am construvcting a number of databases, some of which contain sensitive data and most of which do not. I am attempting to handle the security issues involved in protecting sensitive data in part...
12
by: Sean Davis | last post by:
I am working on a simple script to read from one database (oracle) and write to another (postgresql). I retrieve the data from oracle in chunks and drop the data to postgresql continuously. The...
3
by: =?Utf-8?B?TXJrIEJsYWNrYWxs?= | last post by:
Hi all, This is my first attempt to update an access database in VB.Net 2005. It goes broadly as follows (I have condensed it): Dim MyConnection As New Data.OleDb.OleDbConnection...
1
by: Ragabash | last post by:
I have a problem about updating the old database. I sell a project to a company with old database but I can't update its database. I want a sql code that find the differences between the old end the...
3
by: Neil Domingo | last post by:
I have an online hosted website that uses mysql database. Now, what I am trying to do was to update my remote database. What I mean was, a different mysql database that is not online. I used...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.