How Do I Write An Update Query Across 2 Databases.

Jan 4, 2008

I would like to write a query that will join two tables in separate databases (same server). Then update a field in one table using data and criteria from the other.

Its easy to do this in Microsoft Access by linking the tables using ODBC, but I found its not so simple to do directly in SQL Server

Thanks.





View 2 Replies


ADVERTISEMENT

How Do I Write SQL Query Accessing Multiple Databases (DBFs)?

Aug 8, 2006

I have several database files, all in the same directory. I want to write SQL statements that access two databases at once. For example, if only one database would be involved, I would write:


SELECT     Test_Source_ID_column, Data_column
INTO            Test_Destination_table
FROM         Test_Sources_table
The above query copies two columns (Test_Source_ID_column and Data_column) from Test_Sources_table into a brand new table called Test_Destination_table.
Now the above query is fine for both the old and new tables being in the same database. But what if Test_Sources_table is in file Old.dbf and I want the new table Test_Destination_table to be in New.dbf?
Both Old.dbf and New.dbf are in the same directory. Therefore, there is no security issue about using ......etcpasswords. I should therefore be able to use relative paths. So, I also want to know how I can do that select on two databases in the same directory without typing long, long paths.
Is there a way to do queries that access multiple database files (all database files being in the exact same directory) AND use relative paths or no paths (and certainly not type a full path)?
NOTE 1: I'm using SQLEXPRESS, therefore do not have the SQL Server 2005 tools. I have Visual Studio 2005 Developer Edition with its tools.
 NOTE 2: One table is accessed through ODBC. The other table is accessed through SQLEXPRESS.
 

View 5 Replies View Related

How To Write A SQL Update Query Using Parameters?

Mar 23, 2008

Hi, could someone explain to me with sample code how to write a sql query using parameters to update a record, as I am new to this.

thanks

View 4 Replies View Related

Update Query Joining Tables From Separate Databases

Apr 17, 2008



In database DB1, I have table DB1.dbo.Suppliers1. This table has an ID column of type INT named SUPPL1_ID

In database DB2, I have table DB2.dbo.Suppliers2. This table has an ID column of type INT named SUPPL2_ID
I would like to update DB2.dbo.Suppliers2 based on values from DB1.dbo.Suppliers1 joining on SUPPL1_ID = SUPPL2_ID.

How can I do this in SSIS?

Assumptions:


linked servers are not an option, as I want the SSIS package to be portable and not dependent on server environments.
TIA.

-El Salsero

View 5 Replies View Related

How To Write An Sql Across Multiple Databases

Dec 23, 2005

so, I am trying to write an sql that requires information across two
different database. It's under the same sql server. However, the
location of the tables are from different database.

Any links I can read about that can show me how to write the queries?

Thanks in advance, and merry X'mas.

View 1 Replies View Related

Denormalization, 2 Databases , 1 Read 1 Write Db

May 28, 2008

Hi,
I was reading that many of these high traffic websites actually have 2 databases, 1 database is used ONLY for reads, while the other is for writes.

How does one go about creating such a setup? How does the database where writes are allowed replicated the data to the read only database server?

View 1 Replies View Related

How To Write A Trigger For Update

May 28, 2007

Hello All,
 As we have INSERTED,DELETED tables to trace what values are inserted and deleted, how to write triggers for Updates on the tables.
Your help would be appreciated.
Shiva Kumar

View 3 Replies View Related

UPDATE Method .WRITE

Oct 29, 2007

Hi, this SQL:

UPDATE [dbo].tblCommodity SET sImagePath .WRITE('abcdef', 0, 5)

gives me following error:
Cannot call methods on varchar.

I did it same way as it is in SQL Server Online Help :(

Thanks for ideas,
Martin

View 2 Replies View Related

How Do You Write An UPDATE Store Procedure?

Oct 11, 2006

I have these 3 tables that are related to each other. I am trying to change the brand name of a product and the type of the product. How can I do this? 1 CREATE TABLE Products
2 (
3 ProductID int IDENTITY (1,1) PRIMARY KEY,
4 ProductSKU nvarchar(100) NOT NULL UNIQUE,
5 ProductName nvarchar(255),
6 ProductDescription nvarchar(MAX),
7 isInStock bit,
8 SalePrice decimal (18,2),
9 UnitPrice decimal (18,2),
10 isOnSale bit,
11 isSpecial bit,
12 isActive bit,
13 ProductRating int,
14 ProductImageBig varchar(255),
15 ProductImageMedium varchar(255),
16 ProductImageSmall varchar(255)
17 );
18
19 CREATE TABLE Brands
20 (
21 BrandID int IDENTITY (1,1) PRIMARY KEY,
22 BrandName nvarchar(255) NOT NULL UNIQUE
23 );
24
25 CREATE TABLE Types
26 (
27 TypeID int IDENTITY (1,1) PRIMARY KEY,
28 TypeName nvarchar(150) NOT NULL UNIQUE
29 );
30
31 // The store procedure I am having trouble with.
32
33 CREATE PROC SetProductsSKU_Brand_Type
34 @ProductID int,
35 @BrandName nvarchar(255),
36 @TypeName nvarchar(150),
37 @ProductSKU nvarchar(100),
38 @ProductName nvarchar(255),
39 @isInStock bit,
40 @SalePrice decimal (18,2),
41 @UnitPrice decimal (18,2),
42 @isOnSale bit,
43 @isSpecial bit,
44 @isActive bit
45 AS
46 UPDATE Products, Types, Brands
47 SET [BrandName] = @BrandName, [TypeName] = @TypeName, [ProductSKU] = @ProductSKU, [ProductName] = @ProductName, [isInStock] = @isInStock,
48 [UnitPrice] = @UnitPrice, [isSpecial] = @isSpecial, [isActive] = @isActive
49 FROM Products prod INNER JOIN ProductsBrands pb
50 ON prod.ProductID = pb.ProductID INNER JOIN Brands b
51 ON pb.BrandID = b.BrandID INNER JOIN ProductsTypes tp
52 ON prod.ProductID = tp.ProductID INNER JOIN Types t
53 ON tp.TypeID = t.TypeID
54 WHERE prod.ProductID = @ProductID
55 AND [ProductSKU] = @ProductSKU
56 AND [ProductName] = @ProductName
57 AND [isInStock] = @isInStock
58 AND [UnitPrice] = @UnitPrice
59 AND [isSpecial] = @isSpecial
60 AND [isActive] = @isActive
61 AND b.BrandName = @BrandName
62 AND t.TypeName = @TypeName
  

View 6 Replies View Related

How To Write Script To Update The Database?

Apr 30, 2004

Hi folks,
Do you guys know how to write the Script to update the SQL database? please help me out? For example, the script will update SQL database at 1:00 am every day...some like that?

Thanks,
Vu

View 4 Replies View Related

Trying To Work Out Why My Code Wont Update Or Write To The DB

Jan 7, 2008

hi there, i have been wrestling with this for quite a while, as in my other post http://forums.asp.net/t/1194975.aspx, what someone advised me was to put in try catch blocks ot see whats going on, problem is i have never really done it whit this kinda thing before, and i was wondering if someone could point me in the right direction.
 
For example where would i put the try catch block in here, to show me if its not working public int getLocationID(int ProductID, int StockLoc)
{
// Gets the LocationID (Shelf ID?) for the stock column and product id
// passed
// The SQL will look Something like: string strSQL;
strSQL = "SELECT " + " location" + StockLoc + " " + "FROM " + " tbl_stock_part_multi_location " + "WHERE " + " stock_id = " + ProductID;string sConnectionString = "Data Source=xxxxx;Initial Catalog=xxxx;User ID=xxxx;Password=xxxxx";
SqlConnection objConnGetLocationID = new SqlConnection(sConnectionString);SqlCommand sqlCmdGetLocationID = new SqlCommand(strSQL, objConnGetLocationID);
objConnGetLocationID.Open();int intLocation = Convert.ToInt32(sqlCmdGetLocationID.ExecuteScalar());
return intLocation;
}

View 6 Replies View Related

Using Varbinary(max) And UPDATE .WRITE To Store Data In A Streaming Fashion

Nov 1, 2007

I have the following table:

CREATE TABLE [dbo].[IntegrationMessages]
(
[MessageId] [int] IDENTITY(1,1) NOT NULL,
[MessagePayload] [varbinary](max) NOT NULL,
)


I call the following insertmessage stored proc from a c# class that reads a file.

ALTER PROCEDURE [dbo].[InsertMessage]
@MessageId int OUTPUT
AS
BEGIN


INSERT INTO [dbo].[IntegrationMessages]
( MessagePayload )
VALUES
( 0x0 )

SELECT @MessageId = @@IDENTITY

END


The c# class then opens a filestream, reads bytes into a byte [] and calls UpdateMessage stored proc in a while loop to chunk the data into the MessagePayload column.


ALTER PROCEDURE [dbo].[UpdateMessage]
@MessageId int
,@MessagePayload varbinary(max)

AS
BEGIN


UPDATE [dbo].[IntegrationMessages]
SET
MessagePayload.WRITE(@MessagePayload, NULL, 0)
WHERE
MessageId = @MessageId


END



My problem is that I am always ending up with a 0x0 value prepended in my data. So far I have not found a way to avoid this issue. I have tried making the MessagePayload column NULLABLE but .WRITE does not work with columns that are NULLABLE.

My column contains the following:
0x0043555354317C...
but it should really contain
0x43555354317C...


My goal is to be able to store an exact copy of the data I read from the file.

Here is my c# code:

public void TestMethod1()
{
int bufferSize = 64;
byte[] inBuffer = new byte[bufferSize];
int bytesRead = 0;

byte[] outBuffer;

DBMessageLogger logger = new DBMessageLogger();

FileStream streamCopy =
new FileStream(@"C:vsProjectsSandboxBTSMessageLoggerInSACustomer3Rows.txt", FileMode.Open);

try
{
while ((bytesRead = streamCopy.Read(inBuffer, 0, bufferSize)) != 0)
{
outBuffer = new byte[bytesRead];

Array.Copy(inBuffer, outBuffer, bytesRead);

string inText = Encoding.UTF8.GetString(outBuffer);

Debug.WriteLine(inText);





//This calls the UpdateMessage stored proc
logger.LogMessageContentToDb(outBuffer);
}
}
catch (Exception ex)
{
// Do not fail the pipeline if we cannot archive
// Just log the failure to the event log
}
}

View 7 Replies View Related

Update Data Among Databases

Mar 22, 2004

Hi,

I develop ASP.NET applications and use MS SQL 2000 Enterprise.

Each customer has one database and one custom design application. And, there is a gateway and a central database to get data from all databases.

Supposed there are 10 DBs. I want the data in those 10 databases updating to the central database directly.
So, the gateway can gather all data of 10 DBs from a central DB.

Now, my question is how should I do it in MS SQL 2000? Can I do it with a stored procedure (SP)? If so, how does the SP like?

Or, SP can only perform on it's own DB, but not execute across DBs? If so, how can I do that?

Thanks for advice

View 1 Replies View Related

How To Update Web And Local Sql Server Databases?

May 6, 2007

I am new to programming in SQL and in VB.  I use VWD to create web applications with a Hosted SQL database, locally though the databases are created in SQLExpress through Visual Web Developer.
I have used the SQL Publishing Wizard to upload my local data to the web sql server.  But, I'd like to have the same local database as is on the web, which is being updated by users, both data and user / membership data but am not sure how to create an easy, or even programmatical way to update both databases periodically.
Thank you for your help. 
Cjsteury
 

View 4 Replies View Related

How To Update Remote Databases Easily?

Dec 19, 2001

Hiya!
I'm developing an app. using SQL Server 7 (as the back end) for a company supporting approx. 200 unrelated clients, all in different locations. There is no LAN or WAN connection between them, so we'd probably need to use TCP/IP. The problem is as follows: We have dynamic reports in our app. which are run based on data in two tables. Whenever we add a new report we'd like to send it to all of our clients i.e. update their tables to reflect the additional rows of new report info. How would this best be handled, by DTS or Replication or BCP? And how could it be done with either?

Thanks,
Sarah

View 3 Replies View Related

How To Dynamically Update Existing 50 Databases' Sp?

May 21, 2002

I have 50 MSDE SQL2k servers, each server has around 10 customer databases.
There are 5 stored procecures need to update to 50*10 = 500 databases.
These 5 stored procedures each has many 'Go' keywords and 4 of 5 with more than 8000 characters.
What might be the best way to loop execute them automatically, instead of
isql/w to each database connection to run the script?

I had bumpped by 'Go' keywords error and limitation of max varchar of 8000 error.
thanks for the help
David

View 4 Replies View Related

SQL 2012 :: SELECT / UPDATE On All Databases

Nov 20, 2014

I need assigning a group of users read, write, update (not delete) permission on all user databases. is there any way to do so instead of creating role on each database separately.

View 2 Replies View Related

Update Data Accross 2 Databases

Mar 14, 2008

I have to DBs. One is the original and the other is for testing. They both have similar data structure. Wanted to know if there is a way to update tables contents in one db with data that is in the other one.

View 4 Replies View Related

Compare Two Databases And Update Objects?

Jul 23, 2005

Is there a way to compare two databases one being an olddatabase and the second being a new database, I willupdate the old database's objects to match the new database'sobjects?Is there SQL code that could do this easily?How do you do this if you deal with the same scenario?Thank you

View 2 Replies View Related

Can Reports Update Application Databases?

Feb 18, 2008

we have a new requirement that calls for also (in addition to RS's automatic directory updates) updating an organizational application database with metatdata about instances of scheduled reports, or alternatively having our app query RS's metadata for such info.

So, let's say we have a report called Sales Detail, and it runs at 8am every day of the week for client A thru the scheduling mechanism that comes with RS. Each time it runs to completion, an entry would have to be made in our organizational database representing a new run (instance) of the report under the client for whom it was run, in this case A.

Forgetting for the moment potential issues with a reporting system interfering with the transactional, or vice versa, can datasets in RS also do updates?...or can the scheduling mechanism in RS be extended to also log info to other places?...or is the metadata kept by RS (about instances of reports) easy to get to and decipher, and possibly be extended to record for which client this particular instance was run?

View 1 Replies View Related

Need Help To Write The Query

Sep 13, 2006

Hi, I have a table Projects. This table has ProjectID and Version as PK. The Version starts at 1 and everytime a project is changed, I save the project with the same ProjectID and increase the Version by 1.How can I create a query that get all Projects with the latest Version? Thx

View 1 Replies View Related

How Do I Write This Query?

Oct 28, 2006

I have a Properties table like thisPropertyID   PropertyValue     1              Address     2             City     3             Stateetc.and a UserProfile table like thisUserID   PropertyID   PropertyValue1               1               123 Main Street1                2               Denveretc.How do I write a query that can populate a registration page  with Address,City, State as labels and 123 Main Street, Denver, as TextBox text?

View 4 Replies View Related

How To Write Query For This Using C#?

Feb 10, 2008

Hi,I have included here my webform here.i need some assistance here with code.my webform contains two parts.the 1st part is office info and the 2nd part is client info.i also have two table named office_info and client_info.1st part is populated from the table office_info as soon as the office name is chosen from the dropdownlist.in my scenario,when user selects officename from dropdownlist,then textboxes correspondingto address and email gets populated by the related data from table office_info.2nd part is client info.here there are 3 textboxes(for name,age,address) to collect the data from the client using the form.these data gets posted to new row in table client_info as soon as user clicks on the save button.Now my actual question starts here.when user selects the option from the dropdonwlist the office info displays,now when he fills the client info part and clicks the save button,i want all the data to go to the table client_info in such a way that all the data fromthe client info part plus the id of the office also go along with it.eg: when user clicks the save button.i want data to get submitted in table client_info in this way.(id,name,age,address,off_row_id) (1,jack,25,US,1) here off_row_id is the id from the below table.my table office_info is like this (id,off_name,address,email)                                         eg(1,xyz,ny,xyz@xyz.com)    well can anyone tell me how to write query to do insert,edit,update,delete query in this case using c#  and sql?here is the scenario <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>        Office Info:<br />        <hr />        <br />        Office name:        <asp:DropDownList ID="DropDownList1" runat="server" Width="63px">            <asp:ListItem>ABC</asp:ListItem>            <asp:ListItem>XYZ</asp:ListItem>        </asp:DropDownList><br />        <br />        &nbsp;Address:        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />        <br />        email:        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />        <br />        <hr />        </div>        Client info:<br />        <br />        &nbsp;name:        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />        <br />        &nbsp;age: &nbsp;        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />        <br />        &nbsp;address:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />        <br />        <br />        <hr />        <asp:Button ID="Button1" runat="server" Text="save" />        <asp:Button ID="Button2" runat="server" Text="cancel" />    </form></body></html> thanks.jack.      

View 8 Replies View Related

How To Write Sql Query With Asp.net(C#)?

Feb 11, 2008

 hello everyone. i want to know how asp.net works with sql database. can i have a link to the article where i can perform from basic to advance sql query using asp.net(C#)? (in context of vwd 2005 and sql express ) thanks. jack. 

View 1 Replies View Related

Please Help Me To Write A Sql Query

May 21, 2008

I have two table named tbl_Scale and tbl_NGTrDAMaster
tbl_Scale(ScaleID,ScaleName,ScaleLB,ScaleUB,ScaleSI1,ScaleSI2,ScaleSI3) here scale id is prim key
tbl_NGTrDAMaster(TrDaId,ScaleID,CityTypeID,DAAmount) no prim key
and we get CityTypeID from xml databinder.......
In my form thr is two drop down list one for scale name and another for city type id
this is the data form  tbl_NGTrDAMaster
 17 1 1 555 18 3 1 777 19 3 1 999 8 1 1 777 5 5 1 34634 20 1 1 52352 27 1 1 6666 23 5 1 12412 12 2 1 235235 13 3 1 456456 14 5 1 1000000 15 4 1 60000 16 5 1 90 24 5 1 25123 25 5 1 13124 26 5 1 12412
but i am expecting only one combination of set.....
like 1-1,1-2,1-3,1-4.......but if reenter 1-1 thn we have to restrict that....
please help me....
i am in big trouble......Thanx in advance
If my qes is not clear for everyone...
plz tell me....
i try my lebel best for understand my prob to u.....

View 2 Replies View Related

How To Write This Sql Query?

Jun 2, 2004

i have a table
tab
col1 col2 num
A a 30
A b 20
B a 10
B b 40
C a 50
C b 40

now i want get col1 by distinct col1 ,and order by num, as the result:
col1
C
B
A

so can someone help me to write this "select..."

View 3 Replies View Related

How Can I Write This SQL Query ??

May 17, 2005

Hi
 
I have 2 tables and I want to Get information from that tables by SQL Query but How Can I writ this SQL Query ? .. My target as Follow
 
Class Table
-------------------------------------------------
ClassID       ClassName
1             AA
2             BB
 
Student Table
-------------------------------------------------
StudentID     StudentName   ClassID
1             Student 1     1
2             Student 2     1
3             Student 3     2
4             Student 4     1
5             Student 5     2
6             Student 6     1
 
 
How Can I Writ SQL Query to get result like the following ..
 
--------------------------------------------------
ClassID       ClassName     StudentCount
1             AA            4
2             BB            2
 
 
My SQL Query must get all Class table column plus column content the count of student in each class
 
 
And thanks with my regarding
 
Fraas
 

View 3 Replies View Related

How To Write This Query

May 12, 2006

Hello,
I have a table with fields; T1: Dept, Name, Desc, ModificationDate
How can I group by T1.Name, T1.Desc and bring T1.Dept which has the latest T1.ModificationDate
Can anyone write me this query?
 

View 3 Replies View Related

How To Write This SQL Query?

Nov 26, 2003

CUSTOMER
Name City IndustryType
Abernathy Construction Willow B
Amalgamated HousingMernphisB
Manchester LumberManchesterF
Tri-City BuildersMemphis B

ORDERS
NumberCustNameSalespersonNameAmount
100Abernathy ConstructionZenith560
200Abernathy ConstructionJones1800
300Manchester LumberAbel480
400Abernathy ConstructionAbel2500
500Abernathy ConstructionMurphy6000
600Tri-City BuildersAbel700
700Manchester LumberJones150
800 Abernathy Construction Abel 75000

SALESPERSON
NamePercentOfQuotaSalary
Abel63132000
Baker3846200
Jones2649500
Kobad2739600
Murphy4255000
Zenith59129800

I have got the three tables above.
Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
Thank you very much!

View 1 Replies View Related

How To Write This SQL Query?

Nov 26, 2003

CUSTOMER
Name City IndustryType
Abernathy Construction Willow B
Amalgamated HousingMernphisB
Manchester LumberManchesterF
Tri-City BuildersMemphis B

ORDERS
NumberCustNameSalespersonNameAmount
100Abernathy ConstructionZenith560
200Abernathy ConstructionJones1800
300Manchester LumberAbel480
400Abernathy ConstructionAbel2500
500Abernathy ConstructionMurphy6000
600Tri-City BuildersAbel700
700Manchester LumberJones150
800 Abernathy Construction Abel 75000

SALESPERSON
NamePercentOfQuotaSalary
Abel63132000
Baker3846200
Jones2649500
Kobad2739600
Murphy4255000
Zenith59129800

I have got the three tables above.
Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
Thank you very much!

View 1 Replies View Related

I Appreciate If Anyone Help Me To Write This Query

Apr 5, 2006

User Page Name Permission
vijay customer.aspx 1
vijay customer.aspx 2
vijay customer.aspx 3
vijay user.aspx 2
Rajashekar customer.aspx 1
Rajashekar customer.aspx 2

Where Permission 1 = SAVE
2 = UPDATE
3 = DELLETE

Where I query on User and PageName I want the output as

User Page Name Permission
vijay customer.aspx 1,2,3
vijay user.aspx 2
Rajashekar customer.aspx 1,2

View 2 Replies View Related

Better Way To Write This Query?

Feb 23, 2006

i am assuming there is a better way to write this query (since im not too proficient in SQL)


sql Code:






Original
- sql Code





select client_id from clients where client_id not in
(select schedule_det.client_id from schedule_det,
schedule_mstr where schedule_det.schedule_id=schedule_mstr.schedule_id
and schedule_mstr.status_code!='COMPLETE')






 SELECT client_id FROM clients WHERE client_id NOT IN     (SELECT schedule_det.client_id FROM schedule_det,             schedule_mstr WHERE schedule_det.schedule_id=schedule_mstr.schedule_id            AND schedule_mstr.status_code!='COMPLETE') 

View 2 Replies View Related

How Do I Write This Query

Nov 30, 2004

ok i have table1, table 2 and table 3.

these table have some common feild names. table1,2 and 3 all have a,b,c and d as field names. each table has other field names too but the ones they all have in common are a,b,c and d.

so i would like to write a query that returns all rows from all 3 tables where column d is greater than 5 and less than 10.

so basically i want it to treat the records from all 3 tables ad one big dataset.

how would i write a query to do this.

i know i could say:
SELECT a,b,c,d
FROM table1,table2,table3

but what gets me is the WHERE clause

do i have to say WHERE table1.d >5 AND table1.d <10 OR table2.d>5 AND table2.d <10 OR table3.d>5 AND table3.d <10

??

any guidance please?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved