Update Query From Another Table On Datechanged Field

Nov 26, 2007

Hi all, sorry if this is the wrong place to put this.

I have two tables, both contain address info. I would like to update
address1, address2, city, state, zipcode and country. May be a few
other fields.

The table I am comparing to has many duplicates. The linkage between
the two table is by ssn. However I have one field that is date stamped
as to which is the most current.

How do I get the last date stamped record and update the other table?

update group1 set
address1 = c.address1
address2 = c.address2
city = c.city
state = c.state
zipcode = c.zipcode
country = c.country
from main c, group1 g
where g.ssn = c.ssn and max(lastchanged)

I know the above does not work but it is what I am try to do. Can
anyone help?

TIA!!!!

View 2 Replies


ADVERTISEMENT

Procedure Or Query To Make A Comma-separated String From One Table And Update Another Table's Field With This String.

Feb 13, 2006

We have the following two tables :

Link  ( GroupID int , MemberID int )
Member ( MemberID int , MemberName varchar(50), GroupID varchar(255) )

The Link table contains the records showing which Member is in which Group. One particular Member can be in
multiple Groups and also a particular Group may have multiple Members.

The Member table contains the Member's ID, Member's Name, and a Group ID field (that will contains comma-separated
Groups ID, showing in which Groups the particular Member is in).

We have the Link table ready, and the Member table' with first two fields is also ready. What we have to do now is to
fill the GroupID field of the Member table, from the Link Table.

For instance,

Read all the GroupID field from the Link table against a MemberID, make a comma-separated string of the GroupID,
then update the GroupID field of the corresponding Member in the Member table.

Please help me with a sql query or procedures that will do this job. I am using SQL SERVER 2000.

View 1 Replies View Related

Update Data To A Table From The Sum Of A Field From Another Table Based On Some Criteria

Jan 22, 2008

Hello Friends,

I have two tables, And also I have Sample data in them.

create table X
(y int,
m int,
v int)

insert into X select 2007,1,5
insert into X select 2007,1,3
insert into X select 2007,2,9
insert into X select 2007,2,1

select * from X

Create table Y
(fy int,
fm int,
v int)

insert into Y select 2007,1,0
insert into Y select 2007,2,0
insert into Y select 2007,3,0

select * from X
select * from Y

I want to update the Table Y with the Sum of the Fields V from X based on the Criteria Y.fy = X.y and Y.fm = X.m

Using temporary table cannot be done.

Thanks in Advance,
Babz

View 1 Replies View Related

Transact SQL :: Update A Field In Table Based On Another Table

Nov 17, 2015

I have a daily record table (has field Date1, field2Update) and have another table(has field Date2, Flag (value: 0 and non 0 values)

I want to update table1 and set field2Update as somevalue where table2.Flag <> 0

View 4 Replies View Related

Need Help With Update Query To Populate New Field

Oct 31, 2006

Hi folks:

I have added a new field to an established table, and am having trouble figuring out how to populate its values:

Two tables are involved: Jobs and Parts

There is a one-to-one relationship between each JobID and its PartID

Each Part has a PartPrice. Now I have added to the Jobs table a JobPrice field. Whenever a new Job is created, JobPrice takes the current value of its Part's PartPrice. Each Job's JobPrice remains constant for historical purposes, while the PartPrice may fluctuate at my client's whim.

The trouble is that the Jobs table is 10k+ records large, and I need to fill the JobPrice values. I am at a loss. I know how to commit the update one record at a time:

UPDATE Jobs

SET JobPrice = (SELECT PartPrice FROM Parts WHERE (PartID = [the part in question]))

WHERE (JobID = [the job in question])



My SQL knowledge is limited to basic statements that I use in my .NET work, and I rarely create anything in Management Studio more elaborate than what you see above. Many thanks for your time,

Matt

View 3 Replies View Related

UPDATE Query On Partial Field

Aug 6, 2007

How would I accomplish update just a part of a field? I have 500+ records in a table that got written as \share01234.jpg, \share01235.jpg...\share01734.jpg but the records should have ended with .tif instead. Now the application cannot find the correct image because the extension is incorrect. How can I use the Update statement to just change the extension on these records?

Thanks.

View 3 Replies View Related

Update Field With Max From Another Table

Jul 20, 2005

I have two tables STUDENTS and REGISTRATIONS. I wish to update mySTUDENT table field, LAST_ATTENDED_SESSION_ID from my REGISTRATIONtable of the max SESSION_ID found in the REGISTRATION table.STUDENT starts off with:STUDENT_ID LAST_ATTENDED_SESSION_ID123456789 000000234567890 000000345678901 000000REGISTRATIONS:STUDENT_ID SESSION_ID CLASS_ID123456789 200001 BUS100123456789 200102 BUS150123456789 200203 BUS160I want to update my STUDENT.LAST_ATTENDED_SESSION_ID with theMAX(SESSION_ID) found in REGISTRATIONS for each student.I'd end up with:STUDENT_ID LAST_ATTENDED_SESSION_ID123456789 200203234567890 000000345678901 000000I've found examples here about selects and sub-queries, but nothingyet in my situation with an update.TIARob

View 2 Replies View Related

Just Update A Field On A Table!!!

Aug 23, 2007

I need to update a field on a SQL Server table.
I load a foxpro table and then I need to look on a SQL Server table for a match, once I find a record match I need to update a field on the SQL Server table.

I do not want to upload records!.
Can anybody route me to a good example or feedback to accomplish it.


Thanks,
Sergio

View 1 Replies View Related

Is It Possible To Use This One Query To Update The QUAL_SCORE Field Without Using Cursor

Dec 7, 2007

UPDATE SCORESET QUAL_SCORE = ((SCORE - average_score)/deviation_score)*(-0.25)  +((accuracy_score - accuracy_average_score)/accuracy_deviation_score)*0.25))WHERE SCORES.DISABLEMENT_ZIP = v_disablement_zipAND SCORES.EQPMNT_CODE = v_eqpmnt_code;     
is it possible to use this one query to update  the QUAL_SCORE field without using cursor.if SCORE and deviation_score are 0, Then (SCORE - average_score)/deviation_score)*(-0.25) is 0,if accuracy_score and accuracy_deviation_score are 0, then (accuracy_score - accuracy_average_score)/accuracy_deviation_score)*0.25 is 0.
 
Thanks

View 2 Replies View Related

Creating Query To Update A Field For Multiple Items

May 5, 2015

Looking to write an query that will update a field for multiple items, like 1,500.

something like:

UPDATE INMAST
SET FPRICE = 111.11

WHERE
INMAST.FPARTNO = 'xxx'

only issue I'm having is a need to do a JOIN because there's one more condition that must be met from another table, i've tried this:

SET FPRICE = 111.11
JOIN INVCUR
ON
(inmast.fpartno + inmast.frev)= (invcur.fcpartno + invcur.fcpartrev)

WHERE
INMAST.FPARTNO = 'NRE'
AND
invcur.flanycur = 'TRUE'

but that is giving me an error around the JOIN

View 11 Replies View Related

Automatically Update Datetime Field In A Database Table.

Feb 28, 2006

hi e'body:

I have some database tables, and each one of them have a creation_date and modified_date in them. I was trying to figure out a way where when a row in one of these tables is changed using Enterprise Manager (Database -> Tables -> select table -> right click -> select all rows -> change a field in a row inside a table), is there a way apart from triggers, such that the "modified_date" column for that row get changed to 'getdate()' (rather picks up the current datetime).

thanks in advance.

View 1 Replies View Related

T-SQL (SS2K8) :: Update A Field In 3rd Table From 2 Joined Tables

Jul 29, 2015

I have a script that is supposed to run thru 2 joined tables and update a field in the 3rd table. The script works but takes approx. 4 hours to run against 250k records.

UPDATE a
SET Con_Mailings = STUFF((SELECT '; ' + c.ListName
FROM [server].[xxxxx_MSCRM].[dbo].ListBase c with (nowait)
INNER JOIN [server].[xxxxxx_MSCRM].[dbo].[ListMemberBase] b with (nowait)
ON b.ListID = c.ListID
WHERE b.EntityID = a.TmpContactID
FOR XML PATH('')),1,1,'')
FROM [xx_Temp].[dbo].[Lyris_CombinedTest] a

I should end up with something like this in the con_mailings field:

'Mailing1, Mailing2, Mailing3'

View 9 Replies View Related

Update Time Portion Of The Datetime Field In Sql Table

Apr 21, 2008

I have startdate and enddate. I like startdate to be 4/28/08 12:00:00 and enddate to be 5/4/08 23:59:59. What update statement do i need to run to update table. Currently my table show startdate 2008-04-28 05:00:00.000
enddate 2008-05-04 04:59:59.000.

View 4 Replies View Related

Update Time Portion Of The Datetime Field In Sql Table

Apr 21, 2008

I like to add a day to this date and also make time to 23:59:59. So end result for this table and recrods will be 2008-11-09 23:59:59 and next row 2008-11-16 23:59:59 so on.....
2008-11-08 23:00:00.000
2008-11-15 23:00:00.000
2008-11-22 23:00:00.000
2008-11-29 23:00:00.000
2008-12-06 23:00:00.000
2008-12-13 23:00:00.000
2008-12-20 23:00:00.000
2008-12-27 23:00:00.000
2009-01-03 23:00:00.000
2009-01-10 23:00:00.000
2009-01-17 23:00:00.000
2009-01-24 23:00:00.000
2009-01-31 23:00:00.000
2009-02-07 23:00:00.000
2009-02-14 23:00:00.000
2009-02-21 23:00:00.000
2009-02-28 23:00:00.000
2009-03-07 23:00:00.000

View 3 Replies View Related

Update Time Portion Of The Datetime Field In Sql Table

Apr 21, 2008

I have two table I like to change startdate time to 00:00:00.00 and Enddate time to 23:59:59.000

Table 1
ID Startdate Enddate

418 2008-04-28 05:00:00.000 2008-05-04 05:00:00.000
419 2008-05-05 05:00:00.000 2008-05-11 05:00:00.000
420 2008-05-12 05:00:00.000 2008-05-18 05:00:00.000
421 2008-05-19 05:00:00.000 2008-05-25 05:00:00.000
422 2008-05-26 05:00:00.000 2008-06-01 05:00:00.000
423 2008-06-02 05:00:00.000 2008-06-08 05:00:00.000
424 2008-06-09 05:00:00.000 2008-06-15 05:00:00.000
425 2008-06-16 05:00:00.000 2008-06-22 05:00:00.000
426 2008-06-23 05:00:00.000 2008-06-29 05:00:00.000
427 2008-06-30 05:00:00.000 2008-07-06 05:00:00.000
428 2008-07-07 05:00:00.000 2008-07-13 05:00:00.000
429 2008-07-14 05:00:00.000 2008-07-20 05:00:00.000
430 2008-07-21 05:00:00.000 2008-07-27 05:00:00.000
431 2008-07-28 05:00:00.000 2008-08-03 05:00:00.000
432 2008-08-04 05:00:00.000 2008-08-10 05:00:00.000
433 2008-08-11 05:00:00.000 2008-08-17 05:00:00.000
434 2008-08-18 05:00:00.000 2008-08-24 05:00:00.000
435 2008-08-25 05:00:00.000 2008-08-31 05:00:00.000

Table 2
ID Startdate Enddate
445 2008-11-03 06:00:00.000 2008-11-09 06:00:00.000
446 2008-11-10 06:00:00.000 2008-11-16 06:00:00.000
447 2008-11-17 06:00:00.000 2008-11-23 06:00:00.000
448 2008-11-24 06:00:00.000 2008-11-30 06:00:00.000
449 2008-12-01 06:00:00.000 2008-12-07 06:00:00.000
450 2008-12-08 06:00:00.000 2008-12-14 06:00:00.000
451 2008-12-15 06:00:00.000 2008-12-21 06:00:00.000
452 2008-12-22 06:00:00.000 2008-12-28 06:00:00.000
453 2008-12-29 06:00:00.000 2009-01-04 06:00:00.000
454 2009-01-05 06:00:00.000 2009-01-11 06:00:00.000
455 2009-01-12 06:00:00.000 2009-01-18 06:00:00.000
456 2009-01-19 06:00:00.000 2009-01-25 06:00:00.000
457 2009-01-26 06:00:00.000 2009-02-01 06:00:00.000
458 2009-02-02 06:00:00.000 2009-02-08 06:00:00.000
459 2009-02-09 06:00:00.000 2009-02-15 06:00:00.000
460 2009-02-16 06:00:00.000 2009-02-22 06:00:00.000
461 2009-02-23 06:00:00.000 2009-03-01 06:00:00.000
462 2009-03-02 06:00:00.000 2009-03-08 06:00:00.000

View 1 Replies View Related

View Field Content Update When Real Table Fields Change

Sep 1, 2005

Hi,I use view to join difference table together for some function. However,when the "real" table fields changed (e.g. add/delete/change field). Theview table still use the "old fields".Therefore everytimes when I change the real table, I also needed open theview table and save it by SQL enterprise manager manually for update theview table field.Can we use a SQL command or other method to update it directly?Regards,Silas

View 4 Replies View Related

Using An Exec Query To Insert Pdf, .doc File Into Table From A Dir Path Which Is A Field In Another Table

Aug 5, 2007

I have the following query in sql 2005:


PROCEDURE [dbo].[uspInsert_Blob] (

@fName varchar(60),

@fType char(5),

@fID numeric(18, 0),

@bID char(3),

@fPath nvarchar(60)

)



as

DECLARE @QUERY VARCHAR(2000)

SET @QUERY = "INSERT INTO tblDocTable(FileName, FileType, ImportExportID, BuildingID, Document)

SELECT '"+@fName+"' AS FileName, '"+@fType+"' AS FileType, " + cast(@fID as nvarchar(18)) + " as ImportExportID, '"+@bID+"' AS BuildingID, * FROM OPENROWSET( BULK '" +@fPath+"' ,SINGLE_BLOB)

AS Document"

EXEC (@QUERY)

This puts some values including a pdf or .doc file into a table, tblDocTable.

Is it possible to change this so that I can get the values from a table rather than as parameters. The Query would be in the form of: insert into tblDocTable (a, b, c, d) select a,b,c,d from tblimportExport.

tblImportExport has the path for the document (DocPath) so I would subsitute that field, ie. DocPath, for the @fPath variable.

Otherwise I can see only doing a Fetch next from tblIportExport where I would put every field into a variable and then run this exec query on these. Thus looping thru every row in tblImportExport.

Any ideas how to do this?

View 1 Replies View Related

Trying To Save Editted Textbox Value In Table But Original Value Saves Instead - Trouble With Table Update Query

Jan 9, 2008

This program gets the values of A and B passed in. They are for table columns DXID and CODE. The textbox GET1 is initialized to B when the page is loaded. When I type another value in GET1 and try to save it, the original initialized value gets saved and not the new value I just typed in. A literal value, like "222" saves but the new GET1.TEXT doesn't.

View 1 Replies View Related

UPDATE Query To Update One Table From Another

Sep 15, 2001

I'm looking for a query that can "batch" update one table from another. For example, say there are fields on both tables like this:
KeyField
Value1
Value2
Value3
The two tables will match on "KeyField". I would like to write one SQL query that will update the "Value" fields in Table1 with the data from Table2 when there is a match.

View 1 Replies View Related

SQL Server 2012 :: Update Table Using CTE Or Using Inner Query On Same Table

Jul 29, 2015

To avoid locking/blocking, or in transaction scope, we are trying make a common practice of writing coide for update commands in our all SPs based on primary key columns in where clause. I have a following scenario...

UPDATE [dbo].[TL_CST_Locker_Issuance] SET
[isActive] = 0
WHERE
LockerIssuanceId IN (SELECT LockerIssuanceId

[Code] ...

What is the better approach and should be followed to avoid locks and gain performance or best approach.

View 7 Replies View Related

Query To Know If A Field Exits In A Table

Jan 12, 2006

In MsSQLServer what is the query to kown if a field exists in a table

if exist (select * from dbo.sysobjects where id =...............

????

View 2 Replies View Related

How To Get All Field Names In A Table Using Sql Query?

Sep 11, 2006

Hi,

How canI get all field names in a table using sql query? Now I am not interested in the data in this table, what I am interested in is just the schema, i.e. all field names. Thanks.

View 22 Replies View Related

Help With A Query- Select A Top Field And Join It With Another Table

Feb 1, 2008

 hi, i need help with a query:SELECT Headshot, UserName, HeadshotId FROM tblProfile INNER JOIN Headshots ON Headshots.ProfileId=tblProfile.ProfileId WHERE (UserName= @UserName) this query will select what I want from the database, but the problem is that I have multiple HeadshotIds for each profile, and I only want to select the TOP/highest HeadshotId and get one row foreach headshotId. Is there a way to do that in 1 SQL query? I know how to do it with multiple queries, but im using SqlDataSource and it only permits one. Thanks!

View 2 Replies View Related

Query To Retrieve Records That Sum To A Field In Another Table

May 18, 2012

I really need creating a query that will retreive all records from a table where the dbo.CorpAdv.AcctNum field equals a specific value (for this example "0023"), the TranCode = "R" and the sum of the records, starting with the latest, equals the value of a field in another table (dbo.Master.TotalAdv)

dbo.Master.TotalAdv is numeric (dollar amount) and in this example the value is $1,850.00

dbo.CorpAdv.pID is an integer and unique ID for each record, later records have higher numbers
dbo.CorpAdv.AcctNum is text field
dbo.CorpAdv.AdvAmt is numeric (dollar amounts)

[code]....

View 3 Replies View Related

Treating A Table Field As A Boolean Value In A Query...help!

Feb 29, 2008



I wanted to test how SQL server 2005 works with Boolean values.
so I created this table


SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[BoolTest](

[ID] [int] IDENTITY(1,1) NOT NULL,

[Operand1] [bit] NULL,

[Operand2] [bit] NULL,

CONSTRAINT [PK_BoolTest] PRIMARY KEY CLUSTERED

(

[ID] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]


I populated it like so

insert dbo.booltest (operand1, operand2) values (1,1)

insert dbo.booltest values (1,0)

insert dbo.booltest values (1,null)

insert dbo.booltest values (0,0)

insert dbo.booltest values (0,null)




Then I tried this


select case when operand1 OR operand2 then 'True' else 'False' End
from dbo.booltest where id=1

thinking that since row 1 has 1 and 1 I'll get 'True' as a string showing in the output window

but instead I got this error


Msg 4145, Level 15, State 1, Line 1

An expression of non-boolean type specified in a context where a condition is expected, near 'OR'.


question:
how do you work with bit value table Fields as booleans in a boolean test

many thanks in advance for your time/help
CarlitoA

View 7 Replies View Related

SQL Server 2012 :: Use Select Within A Table Field In 2nd Query

Aug 27, 2015

I have a table (ScriptTable) which holds a groupID Nvarchar(10) ,SQLStatement Nvarchar (150)

Table Fields =
GroupID SQLStatement
1234 Select CUSTNO, CUSTNAME,CUSTADDRESS from custtable where customerNo = 'AB123'
9876 Select CUSTNO, CUSTNAME,CUSTADDRESS from custtable where customerNo = 'XY*'

What I need is to take each select statement in turn and add the data into a temp table. I can use any method but it needs to be the most efficient. There can also be a varying number of select statements to run through each time my job is run.

View 6 Replies View Related

Can I Query Metadata To Find Table The Owns Field?

Mar 9, 2008

I have to write some reports for a database I am not familiar with. Is there a query I can use to find a table name if I know the field name?

example: Select table_name from database where field_name = 'my_field'

Mike

View 1 Replies View Related

Get Value From Query To Update Another Another Table

Oct 26, 2007

I have a query that simply slelcts the min value of a specified fieldfrom one table, I want to take that value to update a field inannother table, just can not figure it out.

View 1 Replies View Related

Update Field With Trigger Only If A Specific Field Is Updated

Nov 11, 2013

I want to update a field with a trigger only if a specific field is updated.

When I try the code below, it updates the field when any field in the record is updated. Is there a way to only make look at picked_dt?

ALTER TRIGGER [dbo].[UpdatePickedDate]
on [dbo].[oeordlin_sql]
after update
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from

[Code] .....

View 4 Replies View Related

How To Update A Table In SQL Query Analyzer?

Nov 15, 2007

 How do I update a table of 600 records with varying amounts of the same branch names say, there are 60 records that are Atlanta etc.Based on the following query that retrieves the Branch Id. Select t1.Branch, t2.SCName, SCID from WWFE07BoothLeads As t1JOIN SMC_New_Products.dbo.SupportCenters As t2ON t2.SCName Like t1.Branch+'%'Update WWFE07BoothLeads Set BoothId = ?(1) Where Branch = ?(Atlanta) 

View 2 Replies View Related

Key/value Pair Table Update Query

Jan 18, 2005

I'm working with a table that I've created called Config which contains key/value pairs used to get and set site-wide settings. I'm now trying to create a web form which updates the table but I'm not sure how to create the most effective UPDATE query.

Table of course takes this form key | value
---------------------------------
config_setting1 | value1
config_setting2 | value2

I'm working with a System.Collections.Specialized.StringDictionary Class object which contains all of the pairs from my webform... anybody have a creative way to build an UPDATE string using this object???

Thanks for any help and suggestions,
ecolner@yahoo.com

View 1 Replies View Related

Update Table With A Loop Through A Query?

Sep 20, 2013

I want to make a SP to update table Product with information I get from table Orderdetail.

Create Procedure UpdateVoorraad
§OrderId (int)
As
Select ProductId, Tal From Orderdetail where OrderId = @OrderId

-- this query get info from table orderdetail : ProductId (integer) and Tal (smallint)

-- Tal = Number of Products

-- Here I want to loop through the query above

-- and for each record in the query I want to update

-- table Product.

Update Product Set Product.Voorraad = Product.Voorraad - Tal where ProductId = ProductId

To do this must I make a create a tempory table, store the query result in the table loop through the table and update table product, or can I try to create a function without a temporary table.

View 3 Replies View Related

Update Table Using Sub-query With Expression

Jan 17, 2014

Here is what I have:

UPDATE A SET ConsumerLogon =
(SELECT email FROM TABLE B
WHERE userNumber = LEFT (A.ConsumerLogon ,CHARINDEX ( '@' , A.ConsumerLogon , 1 ) -1) )

Seems like the subquery expression does not receive ConsumerLogon from the outer query.is this possible to refer to outer query in subquery expression?

View 4 Replies View Related







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