Updating A Table Depending On 2 Databases

Dec 3, 2007

In a package we have statements pointing to 2(or more) different databases on the server. When moving between environments, is there an easy way to change statements like:

UPDATE t1
SET t1.name = t2.name,
t1.age = t2.age
FROM DB1..Person t1
INNER JOIN DB2..PersonToo t2
ON t1.PersonID = t2.PersonID

I can think only of building the statements replacing the database names with variables, but that's not an easy way. I do not know how to use package variables in this situation.
1 way of doing this may be by using a Lookup or Conditional Split and use the resulting dataflow in a SP or such to update, using parameters...
It all sounds very messy, and I still don't know how
Any ideas?


TIA,

View 7 Replies


ADVERTISEMENT

T-SQL (SS2K8) :: Updating Statement Depending On 2 Fields

Sep 30, 2015

I need to build an update query for all my article beginning with '0.%' for my varchar field refkey, but depending on some conditions.

For example.
Case st.base <> '' and st.qttbase <> 0
Theo refkey = B
Case st.cos <>'' and st.qttcos <> 0
Then refkey = C
Case st.refo <> '' and st.qttrefo <> 0
Then refkey = R

But my problem are That i can have Many combination on refkey, for example:

B,BC,BCR,C,CB,CBR,R...and so on.

Also i need to separate the letters with comma, like:

B
B,C
B,C,R
.....

View 6 Replies View Related

Updating Similar Multiple Table In Different Databases Automatically

May 16, 2008



Hi Guys

I have 4 databases in the same space.My users use all of them and use the same username and password to log into these 4 databases.In each of these databases,i have put a control table to allow me to keep track of all users that have to reset their passwords.

The control table consists of the username and flag fields.When the flag is ON(1) the user is forced to reset thier password and if the flag is OFF(0) they are not.

When a user logs into any one of these databases and they have to reset thier password,how do i make sure that all the other tables in other databases are also updated to make sure that the user is not forced to reset their password again when they log into those other databases later since they are using the same username and password for all databases.

I am planning to use a stored procedure which i will put into all the four databases and when a user logs in and has to reset their password,that sproc is called and automatically updates all the other 3 tables in other 3 databases.

Some SQL examples will be very appreciated.

Thanks.



View 5 Replies View Related

Update Table 1 To Table 2 Depending Date Time &#043; ID

Apr 26, 2008

need help please on update only if .

i need to update only the field "val_holiday " (in table B from table A)

and olso to check on table B the "ID" + "new_date" only if exist

and update the field "val_holiday " (in table B)

and at the end of update change the field "field_check_update_if _ok" from 0 to 1
only the row that update in table B


select from table A

update table B

WHERE ..........................HOW ?




----------------------------------------------------------------- table A

ID fname new_date val_holiday field_check_update_if _ok

---------------------------------------------------------------------------------------------------

111 aaaa 15/03/2008 999 0

111 aaaa 16/03/2008 888 0

111 aaaa 18/03/2008 77 0

111 aaaa 19/03/2008 9 0

111 aaaa 20/03/2008 111 0

111 aaaa 21/03/2008 12 0



222 bbb 02/05/2008 15 0

222 bbb 03/05/2008 16 0

222 bbb 04/05/2008 9 0

222 bbb 05/05/2008 3 0

222 bbb 06/05/2008 90 0

222 bbb 07/05/2008 3 0

222 bbb 08/05/2008 3 0

222 bbb 09/05/2008 3 0



333 ccc 03/04/2008 4 0

333 ccc 04/04/2008 4 0



----------------------------------------------------------------- table B

ID fname new_date val_holiday

----------------------------------------------------

111 aaaa 15/03/2008 1

111 aaaa 16/03/2008 1

111 aaaa 18/03/2008 1

111 aaaa 19/03/2008 1

111 aaaa 20/03/2008 1

111 aaaa 21/03/2008 1



222 bbb 02/05/2008 3

222 bbb 03/05/2008 3

222 bbb 04/05/2008 3

222 bbb 05/05/2008 3

222 bbb 06/05/2008 3

222 bbb 07/05/2008 3

222 bbb 08/05/2008 3

222 bbb 09/05/2008 3



333 ccc 03/04/2008 4

333 ccc 04/04/2008 4

------------------------------------------------------------------------------

TNX for the help and for all

View 1 Replies View Related

Update Table A To Table B Depending Date Time + ID

Apr 25, 2008

need help please on update only if .
i need to update only the field "val_holiday " (in table B from table A)
and olso to check on table B the "ID" + "new_date" only if exist
and update the field "val_holiday " (in table B)


and at the end of update change the field "field_check_update_if _ok" from 0 to 1
only the row that update in table B




Code Snippet
select from table A
update table B
WHERE ..........................HOW ?




----------------------------------------------------------------- table A
ID fname new_date val_holiday field_check_update_if _ok
---------------------------------------------------------------------------------------------------

111 aaaa 15/03/2008 999 0
111 aaaa 16/03/2008 888 0
111 aaaa 18/03/2008 77 0
111 aaaa 19/03/2008 9 0
111 aaaa 20/03/2008 111 0
111 aaaa 21/03/2008 12 0

222 bbb 02/05/2008 15 0
222 bbb 03/05/2008 16 0
222 bbb 04/05/2008 9 0
222 bbb 05/05/2008 3 0
222 bbb 06/05/2008 90 0
222 bbb 07/05/2008 3 0
222 bbb 08/05/2008 3 0
222 bbb 09/05/2008 3 0

333 ccc 03/04/2008 4 0
333 ccc 04/04/2008 4 0


----------------------------------------------------------------- table B
ID fname new_date val_holiday
----------------------------------------------------

111 aaaa 15/03/2008 1
111 aaaa 16/03/2008 1
111 aaaa 18/03/2008 1
111 aaaa 19/03/2008 1
111 aaaa 20/03/2008 1
111 aaaa 21/03/2008 1

222 bbb 02/05/2008 3
222 bbb 03/05/2008 3
222 bbb 04/05/2008 3
222 bbb 05/05/2008 3
222 bbb 06/05/2008 3
222 bbb 07/05/2008 3
222 bbb 08/05/2008 3
222 bbb 09/05/2008 3

333 ccc 03/04/2008 4
333 ccc 04/04/2008 4
------------------------------------------------------------------------------
TNX for the help and for all

View 5 Replies View Related

T-SQL Create Self-reference In Depending Table

Jul 23, 2005

Hello all,I have two tables - Projects and ProjectStructTable Projects contains master records of the projects, ProjectStructallows to define a project herarchie and contains the fieldsPrjStructId, ProjectId, PrjStructName, ..., ParentIdPrjStructParent contains a reference to the parent or to itselves ifrecord is top-level-record for a project.I try to create a trigger on table Projects (INSERT) whichautomatically creates the top-level-entry in ProjectStruct but Ididn't succed.Tried to use (several variations similar to)INSERT INTO ProjectStruct (ProjectId, PrjStructName, ParentId)SELECT prjProjectId, 'top-level',IDENT_CURRENT('ProjectStruct'))FROM INSERTEDbut this inserts a reference to the last inserted record. Why thishappens is pretty clear to me, but I found no way to get the referenceto the identity column of the record currently inserted.Is there a way to do this?

View 7 Replies View Related

Updating Of The Tables In Two Different Databases

Dec 16, 2001

I am using SQL server7.0. I am having two databases ,say database A and database B.Database A is the main database which is used in two /three projects.While database B is created by me for my work.From the database A, I am using the 4/5 tables, which i have copied in to the database B.
So, i want to update these tables in the database B as soon as any change (insert,update or delete ) occures on the tables in the database A.
That's why I am interested in doing these work.I have tried, but it doesn't work.So, I have placed these into these forum.
Is any body is having the trigger, procedure ready for doing these job. then plz,mail it to me

View 1 Replies View Related

Updating Multiple Databases

Jun 25, 2002

I have a problem like this. I have an application which shud be internet hosted. All transactions should be updated to the central server of the net as well as an intranet DB server. (I'll have a DB server - SQL Server 2000 in each intranet). Is this possible.. i'm planning to use ASP to develop the net based application.
Thank you in advance..
Geetha R

View 2 Replies View Related

Databases Updating Simultaneously

Aug 31, 2006

Hi,I have managed to create a second copy of my "live" database, forsoftware testing purposes.Inspecting the properties of the new database, everything seems inorder. The logical file name is the same, which I believe is fine, andthe physical database (and log file name) is different.However, despite the fact that there is no application currentlyaccessing the "testing" copy, both databases are seemingly beingupdated simultanously. I can tell this from the physical file sizes onthe server, which are identical, and growing at the same rate.Does anyone have any suggestions why this might be happening - and howI can stop it?Thanks in anticipation!Phil

View 1 Replies View Related

Altering Strings Depending On Data In A Table.

Sep 10, 2007

Hi Guys,

I'm wondering if an idea I'm playing with is feasible and if so, how you would recommend implementing it.

Let's say I have a Dictionary table, 2 columns:

Word | Definition

And I have a string - "The cat sat on the dog"

If there's a definition for "cat" in the dictionary table, I want to alter the string so it becomes "The >>cat<< sat on the dog"

At the same time, if there's also a definition for "dog" then my string now becomes "The >>Cat<< sat on the >>Dog<<"

The idea being that when I manipulate the data in my ASP I can replace() the >><< with specific HTML code. (I'm trying to recreate the "in text" advertising thing that lots of people seem to be using - but not doing adverts, just information for our users - Someone hovers over a highlighted word, and with a little bit of Ajax, I can pull the definition out...

I'm not sure (but I'm suspecting) that it would make more sense to do this as I'm storing the string in a table, rather than as I'm pulling it out ready for use (don't want to be slowing my end users down )

Any ideas?

Thanks in advance
-Craig

View 4 Replies View Related

Insert Data Depending On Year Value In Table

Jul 15, 2004

Hi there,

Can anyone help? I currently have this query that imports distinct data into a prices table with a couple of contraints. This table became to large so I have now split this down into yearly tables (dbo.price --> dbo.price2001, dbo.price2002 etc). I get the data each day in another table that may contain data for different years so I need to be able to look at this data and insert into the right yearly tables.

E.g. present query:

Insert Prices
select distinct M.ids, C.zdateT, 1.0,0 from mapid as M,datacorrect as C
where M.asset = 'money'
and C.zDate not in (select zdate from price where sid >=15)


So I need to run this query for each yearly table with a date listed in the datacorrect table (insert prices(yr) yr = 2002,2003,2004 etc)

Any ideas would be appreciated!!

Thanks

S

View 3 Replies View Related

Table Visiblity Depending On Filter Selection

Apr 21, 2008

H, need help please!

I have two tables on a reports, each having it's own dataset.

I want to set the visibility of the table depending on the filter selection.

So if the user selects: show open then show only the table with the open dataset.

I don't now how to this using the expression in the visibility expression.

Please Assist!

Regards

View 2 Replies View Related

Hiding A Table Row Depending On Page Number?

Jul 5, 2007

Hi, Everyone.
i am wondering if there is some way to hide a table row depending on the page number.
I have tried to find a way to access the global page number to use it in an expression for the visibility property on the table row, but i havent found anything useful.

View 14 Replies View Related

Set Visibility Of An Image Depending On If A Certain Table Has No Rows

Aug 22, 2007

Hi,

I'm wondering if it's possible in SSRS 2005 to have an image's hidden expression to depend on if some table in the report has no rows.

Thanks,
Liron

View 4 Replies View Related

Updating A Table By Both Inserting And Updating In The Data Flow

Sep 21, 2006

I am very new to SQL Server 2005. I have created a package to load data from a flat delimited file to a database table. The initial load has worked. However, in the future, I will have flat files used to update the table. Some of the records will need to be inserted and some will need to update existing rows. I am trying to do this from SSIS. However, I am very lost as to how to do this.

Any suggestions?

View 7 Replies View Related

Updating Local And Remote Databases

Jun 10, 2004

Hello everyone.

I'm currently trying to figure out a good way to keep my Local and Remote Databases in sync. Whenever I make changes to one or the other I spend a lot of time manually adjusting the other to match. I want to be able to set up an update page that accesses my Remote database and Local database and Updates the two accordingly.

I really don't know where to start with this one. I'm not sure at all as to how to simultaneously connect to two different databases, on two different servers, and Udate from one another. Does anyone know any good articles to get me started?

Thanks ahead for your replies.

-Alec

View 1 Replies View Related

DB Design :: Update List Of Records In A Table With New Value Depending On Old Value

Jun 15, 2015

I have a table called acc1152 with the field accno. depending on what the value of this field is, i need to replace it with a new value. These are the values i need to update

old value new value
7007 4007
7008 4008
4008 7
7009 4009
7011 4011
4011 ' '
7010 4010
4010 1
7016 4016
4016 1
4506 4006
4512 4012

how do I write one query that will accomplish this?

View 3 Replies View Related

SQL 2012 :: Insert ID Column Value Into Table Depending Upon Input Filename

May 19, 2015

I am loading files with same format from two different locations in to one database. First, my SSIS connects to location 1.

Lets Say
Location1 : C:LoadFilesImport
Location2 : D:LoadFilesImport

Location one has three different set files starting with

First Set: AP_1, AP_2,AP_3,
Second Set: VD_1, VD_2, VD_3,
Third Set: BK_1,BK_2,BK_3,

This SSIS set to run every 3 hours, if it finds files of any set load them. While loading it has to insert into a derivedcolumn called CustID. If the file name Starts with AP_ , custiD values should be as 101

AP_1 goes to Table1
AP_2 goes to Table2
AP_3 goes to Table3

If the file name Starts with VD_ , custiD values should be as 201
If the file name Starts with BK_ , custiD values should be as 301

after processing all these files in first location, the SSIS looks for files in second location and does the same?

--How to achieve CustID depending upon file name ?

View 0 Replies View Related

Transact SQL :: Usage Of OUTPUT Clause Depending On Temporary Table

Jul 14, 2015

Suppose we have the following table in our database;

CREATE TABLE [dbo].[PERMISSION](
[ID] [int] IDENTITY(1,1) NOT NULL,
[USERID] [int] NOT NULL,
[STARTTIME] [smalldatetime] NOT NULL,
[ENDTIME] [smalldatetime] NOT NULL,
[REASON] [nvarchar](250) NULL,
[PERMISSIONTYPEID] [int] NOT NULL,

[code]....

This code works pretty well. But I don't want to do this with "select" since there is OUTPUT clause in T-SQL. So the CommandText property will be changed into this;

command.CommandText = @"insert PERMISSION
output INSERTED.ID, INSERTED.CREATETIME into @outID, @outCREATETIME
values(2, getdate(), getdate(), 'sdfg', 1, DEFAULT);";

well, not only this statement gives an error while executing; but also, no such usage defined in the

documentation of OUTPUT Clause. Actually the documentation tell us to use Temporary Tables for that. So I have to change CommandText into this;
command.CommandText = @"DECLARE @MyTableVar table(ID int, CREATETIME smalldatetime);
insert PERMISSION
output INSERTED.ID, INSERTED.CREATETIME into @MyTableVar

code]....

No temporary tables required; thus, no "type spesific" things required. This way is easier to create dynamic queries though. Only,the RETURNING INTO clause.So, I was wondering; why MS-SQL (T-SQL) forces users to "declare a temporary table (type specific)" and "execute select on the temporary table in order to assign values to output parameters" while using "the OUTPUT Clause". Comparing to the Oracle's sample I'm just using "the RETURNING INTO Clause in order to assign values to output parameters" and that's it; very easy and dynamic. To Summarize, Oracle's RETURNING INTO Clause is better than MS-SQL's OUTPUT Clause, but in fact they're doing the same job.

View 7 Replies View Related

SQL 2012 :: Disable Logins Automatically Depending Upon Expiry Date In A Table?

Jun 4, 2014

Disable logins on access expiry date(Not windows password expiry). we grant access to users on databases only for 60 days. So access is only valid for 60 days. Then the user should again request access to the database going thru security clearance. Thn the DBA's enable the login. Maintaining all these logins of users manually is causing more confusion.
As we know, we dont have any inbuilt functionality to automatically disable logins in SQL Server.

I have a table where the logins and expirydate were recorded in a DB.

Using this table and SQL Server agent. Can i achieve this process automated ?
CREATE TABLE [dbo].[LoginsExpiry](
[LoginName] [varchar](50) NULL,
[ExpiryDate] [date] NULL,
[Roles] [varchar](500)
) ON [PRIMARY]
GO

View 3 Replies View Related

Database Automatically Creates Xxx_Temp Table While Modifying / Updating Table Structure .

Dec 16, 2007

Hello friends,

I am new to the SQL Server 2005 development.

From last 1 week or so, i have been facing very strange problem with my sql server 2005s database
which is configured and set on the hosting web server. Right now for managing my sql server 2005 database,
i am using an web based Control Panel developed by my hosting company.

Problem i am facing is that, whenever i try to modify (i.e. add new columns) tables in the database,
it gives me error saying that,

"There is already an object named 'PK_xxx_Temp' in the database. Could not create constraint. See previous errors.
Source: .Net SqlClient Data Provider".

where xxx is the table name.

I have done quite a bit research on the problem and have also searched on the net for solution but still
the problem persist.

Thanks in advance. Any help will be appreciated.

View 5 Replies View Related

Updating A Table Data From Another Table Using Sql Server 2000

Jun 4, 2008

Hi All,
I have a Problem while updating one table data from another table's data using sql server 2000.
I have 2 tables named TableA(PID,SID,MinForms) , TableB(PID,SID,MinForms)
I need to update TableA with TableB's data using a single query that i have including in a stored procedure.

View 2 Replies View Related

Trigger For Updating Value On One Table When That Value Is Updated On Base Table

Jul 30, 2015

If the id1 will change in table1 it should also change the corresponding id1 field in table2 it does not do anything.

CREATE TRIGGER [dbo].[IDCHANGE]
ON [dbo].[table1]
AFTER UPDATE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from

[Code] .....

View 1 Replies View Related

SQL Server 2014 :: Updating A Column In One Table From Another Table

Dec 23, 2013

We have two tables with names X and Y.

X has a,b columns. And Y has c,d columns.

I want to update b column in X table with the values from d column in Y table on condition X.a=Y.c.

View 3 Replies View Related

Updating Table Referencing 2nd Table Using Case

Feb 9, 2008

Hi

Im trying to create an update statement which references two tables (join) and has a CASE clause attached. Not sure where im going wrong...

Using T-sql!!!

update import set import.gone =
from import
inner join stat
ON stat.id = import.id
CASE
WHEN stat.A = import.field2 THEN import.gone = sec.A
WHEN stat.B = import.field2 THEN import.gone = sec.B
WHEN stat.C = import.field2 THEN import.gone = sec.C
WHEN stat.D = import.field2 THEN import.gone = sec.D
WHEN stat.E = import.field2 THEN import.gone = sec.E
WHEN stat.F = import.field2 THEN import.gone = sec.F
ELSE import.gone = null
END

Any help would be greatly appreciated

View 3 Replies View Related

Updating A Table With Data From A Temp Table

Oct 19, 2007

I am trying to update a table in one database with data from a temporary table which i created in the tempdb.

I want to update field1 in the table with the tempfield1 from the #temp_table

The code looks something like this:

Use master
UPDATE [dbname].dbo.table
SET [dbname].dbo.table.field1 = [tempdb].dbo.#temp_table.tempfield1
WHERE ( [dbname].dbo.table.field2= [tempdb].dbo.#temp_table.tempfield2
AND [dbname].dbo.table.field3= [tempdb].dbo.#temp_table.tempfield3
AND [dbname].dbo.table.field4= [tempdb].dbo.#temp_table.tempfield4)

I get the following error:
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "tempdb.dbo.#temp_table.tempfield2" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "tempdb.dbo.#temp_table.tempfield3" could not be bound.
Msg 4104, Level 16, State 1, Line 2
The multi-part identifier "tempdb.dbo.#temp_table.tempfield4" could not be bound.

What is wrong?

View 1 Replies View Related

SQL Server 2008 :: Insert Data Into Table Variable But Need To Insert 1 Or 2 Rows Depending On Data

Feb 26, 2015

I am writing a query to return some production data. Basically i need to insert either 1 or 2 rows into a Table variable based on a decision as to does the production part make 1 or 2 items ( The Raw data does not allow for this it comes from a look up in my database)

I can retrieve all the source data i need easily but when i come to insert it into the table variable i need to insert 1 record if its a single part or 2 records if its a twin part. I know could use a cursor but im sure there has to be an easier way !

Below is the code i have at the moment

declare @startdate as datetime
declare @enddate as datetime
declare @Line as Integer
DECLARE @count INT

set @startdate = '2015-01-01'
set @enddate = '2015-01-31'

[Code] .....

View 1 Replies View Related

Updating A Table

Aug 22, 2004

I want to write trigger code to update values in table1 to table2.
ALTER, CREATE, DROP cannot be used in a trigger, I guess.

Tabel1
ID, Name, Asset, Date, Active
---------------------------------
1, A, 10 , 01/08/04 Y
1, B, 16 , 06/08/04 Y
1, C, 12 , 07/08/04 Y
1, D, 13 , 10/08/04 Y
2, E, 10 , 15/08/04 Y
2, F, 11 , 16/08/04 Y
2, Y, 12 , 01/08/04 N
2, G, 15 , 17/08/04 Y
3, H, 13 , 19/08/04 Y
3, I, 15 , 02/08/04 N

Table2 after update
ID, Name1, Asset1, Date1, Name2, Asset2, Date2, Name3, Asset3, Date3, Name4, Asset4, Date4
---------------------------------
1,B,16,06/08/04,D,13,10/08/04,C,12,07/08/04,A,10,01/08/04
2,F,11,16/08/04,E,10,15/08/04,blank,blank, blank..
3,H,13,19/08/04,blank, blank...

As you can see, code must select only active('Y') names in table1 arrange in descending order of asset for each ID and updates(or insert into?)table2.
Please help me with code

View 3 Replies View Related

Updating Table From One Db To Another

Jan 18, 2006

How do I update a table from another table which resides in a different database but on the same server. Example Update table a which is in database 1 from table b which is database 2. Please help I need this as soon as possible. Thanks in advance to anyone who can help.

View 3 Replies View Related

Updating A Table

Nov 14, 2006

i have 3 following tables

Accidents, Vehicles, Casualties. the relationship is many vehicles to an accident and many casualties to a an accident.

I have one new table which will contain all the vehicles related to all accidents. however i want to be able put in all casualties that every vehicle is related to..so within the new table, there are three severities of casualties
Vehicledetails
column severity1 severity2 severity3

For every vehicle where there is 0 or more casualties I want to be able put a (total )number for each category of casualty( severity in the VehicleDeatils table ) into the columns in vehicledriverdetails

how can i do this?? i dont want ot have to manually update every single entry one by one...

View 6 Replies View Related

Updating A Table From Another

Jul 5, 2005

I am trying to update one table with information from another - which became corrupt. The data layout is the same. cand_id below is the key, and thus can only returnb a single value. Any help is most appreciated. Thanks. This is the attempt I took:

update mwm.jf_candidates C

set c.ed_occ = x.ed_occ

from mwm.jf_candidates C, mwm.jf_candidates_corrupt X

where c.cand_id = x.cand_id

View 3 Replies View Related

Updating A Table

Aug 30, 2004

I know this is probably really obvious but I am trying to insert values into columns into a table if a client exists and I can't for the life of me figure out the syntax. It is something like this:


table A
Client_Id Field 1 Field 2


Insert (Field1) into Table_A
Select field1 from table_B
Where Table_B.Client_Id = Table_A.Client_id


Thanks.

View 4 Replies View Related

Updating From One Table To Another

Jan 13, 2005

Whenever I run this query Iget the following error message. Can anyone tell me why. I get the same error with or without the "Distinct"

Query:

update Clients
set Clients.Siccode = (Select distinct updateSIC.siccode
from updateSIC
where Clients.accountnumber = updateSIC.accountnumber)

Error Message:

Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

Thanks

View 4 Replies View Related







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