Update Records Just Selected (in One Query)

Mar 28, 2006

I have a stored procedure that I give some parameters and it joins a couple of tables and returns the results.  I would like to know how to update the records in one of the original tables before returning results.

CREATE Procedure dbo.DS_GetSomething(
@someValue char(5)
AS

Select table1.* ,table2.* FROM table1 left inner join table1.itemid on table2.itemid where table2.someValue = @someValue

The table has a field of IMPRESSIONS that I would like to do something like:

;UPDATE table1 set impressions=impressions + 1 where recordid=??

I don't know how to access the recordids I just got from the original select statement.

Thanks for any help

Greg

View 7 Replies


ADVERTISEMENT

Retrieving Selected Records

May 29, 2001

Hi every body,
I am making a program which is currently dealing with thousands of records.
What I want is to have a button in the front END which make me able to fetch only first 100 record.If the desired record doesn't come with in first 100 record I press this button another time to fetch next 100 records i.e. from 101 to 199.
How can it be possible in SQL Server stored procedure.

Eagerly waiting from all of you GENIUS people.
Kailash

View 1 Replies View Related

Update Query Not Upadting Records?

Aug 19, 2007

dear experts,
The code written below doesnt report any error and doest serve the objective of updating the record in the database. Can you please suggest what can be the problem?
 Public Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conLath As SqlConnection        Dim comLath As SqlCommand        Dim upcmd
        conLath = New SqlConnection("Data Source=heybabe1;Initial Catalog=sexsg;User ID=sa;Password=password")        conLath.Open()
        upcmd = "Update Hist set sett_price=@s_p, post_close=@p_s, vol_oq=@v_oq where hist_id=@hid"
        comLath = New SqlCommand(upcmd, conLath)
        comLath.Parameters.Add("@s_p", Data.SqlDbType.Decimal, 8)        comLath.Parameters.Add("@p_s", Data.SqlDbType.Decimal, 8)        comLath.Parameters.Add("@v_oq", Data.SqlDbType.Int, 8)        comLath.Parameters.Add("@hid", Data.SqlDbType.Int, 8)
        comLath.Parameters("@s_p").Value = IIf(sett_price.Text = "", DBNull.Value, sett_price.Text)        comLath.Parameters("@p_s").Value = IIf(post_close.Text = "", DBNull.Value, post_close.Text)        comLath.Parameters("@v_oq").Value = IIf(vol_oq.Text = "", DBNull.Value, vol_oq.Text)        comLath.Parameters("@hid").Value = Request.QueryString("hid")
        Try
            comLath.ExecuteNonQuery()            Response.Redirect("admindata.aspx")
        Catch ex As SqlException            If ex.Number = 2627 Then                Message.InnerHtml = "ERROR: A record already exists with " _                   & "the same primary key"            Else                '     Message.InnerHtml = "ERROR: Could not update record, please ensure the fields are correctly filled out"                Message.InnerHtml = ex.Number                Message.Style("color") = "red"            End If        End Try        comLath.Dispose()        conLath.Close()
    End Sub

View 5 Replies View Related

Retrieving Selected Join Records

Nov 22, 2006

Hi,
I have the folowing 3 (SS2005) tables:


CREATE TABLE [dbo].[tblSubscription](
[SubscriptionID] [int] IDENTITY(1000000,1) NOT NULL,
[SubscriberID] [int] NOT NULL,
[Status] [int] NOT NULL,
[JournalID] [int] NOT NULL,


CREATE TABLE [dbo].[tblTransaction](
[TransactionID] [bigint] IDENTITY(100000000,1) NOT NULL,
[TransactionTypeID] [int] NOT NULL,
[SubscriptionID] [int] NOT NULL,
[Created] [datetime] NOT NULL,


CREATE TABLE [dbo].[tblMailing](
[MialingID] [bigint] IDENTITY(1000000000,1) NOT NULL,
[SubscriptionID] [int] NOT NULL,
[MailTypeID] [int] NOT NULL,
[MailDate] [datetime] NOT NULL


So for each subscription there can be 1 or more transactions and 0 or
more mailings, and the mailings are not necassarily related to the
transactions. What I am having difficulty doing is this:


I wish to select tblMailing.MailingID, tblMailing.MailDate,
tblMailing.SubscriptionID (or tblSubscription.SubscriptionID),
tblSubscription.SubscriberID, tblSubscription.Status,
tblTransaction.TransactionID, tblTransaction.Created, but I only wish
to retrieve rows from the transaction table where
tblTransaction.Created is the latest dated transaction for that
subscription.
I.E. (maybe this makes more sense..:) I wish to select all rows from
tblMailing along with each mailing's relevent subscription details,
including details of the LATEST TRANSACTION for each of those
subscriptions.


I am currently working along the lines of MAX(tblTransaction.Created)
and possibly GROUP BY in a subquery, but cannot quite figure out the
logic.


Any help appreciated.


Thanks, KoG

View 4 Replies View Related

Query To Update 1 Record In A Duplicate Set Of Records

Jul 3, 2007

How do I update a record that has duplicates. For example, I have 3612 orders some of these orders have multiple orderid's I want to update the record for each of these orders that was added most recently.

View 5 Replies View Related

Update From Selected Row

Apr 30, 2007

Hi,

I am having a problem updating one field in a table the update should be the product of two other fields from the same row.
There are atleast 3000+ records need to be updated here.


e.g.

update A
set A.b = A.c * A.D

here b c and d are from same row .. I was wondering if someone knows how to solve this problem.

Thanks in advance.

View 8 Replies View Related

How To Count Number Of Selected Records And Store Result To Another Column

Jul 4, 2012

Code:

SELECT ((ACOS(SIN(34.37769 * PI() / 180) * SIN(latitude * PI() / 180)
+ COS(34.37769 * PI() / 180) * COS(latitude * PI() / 180) * COS((132.404738 - longitude)
* PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS ranges FROM completeyuubinwithlatlon having ranges<=3

First, I have that code whenever i disregard the "having ranges<=3" it selects record but when I include it it returns error. The problem is I want to just select records with ranges less than 3 miles..how do I do that.. and I want to count the number of selected rows and store it on a column on the same table.

View 3 Replies View Related

Update The Selected Rows Before Returning Them In One Command.

Mar 14, 2008



Hello,

I have an external process that polls message rows from a table. apon taking them, it also needs to mark them as taken. there is a status column in the table. marking messages as taken will change the value of status.

How can i perform both these operations in one command? Select the top x rows where their status is equal 1, then update the status of those same rows to a value of 5 for example.

I could iterate through the result of hte intial select and change the status 1 by 1 using a cursor, but this seems like a slow option.

Any other ideas?

Thank you.

View 4 Replies View Related

Trouble Writing Stored Procedure To Retrieve Records By Selected Month And Year

May 15, 2007

hi,
i am a nubie, and struggling with the where clause in my stored procedure. here is what i need to do:
i have a gridview that displays records of monthly view of data. i want the user to be able to page through any selected month to view its corresponding data. the way i wanted to do this was to set up three link buttons above my gridview:
[<<Prev]  [Selected Month]  [Next>>]
 the text for 'selected month' would change to correspond to which month of data was currently being displayed in the gridview (and default to the current month when the application first loads).  
i am having trouble writing the 'where' clause in my stored procedure to retrieve the selected month and year.
i am using sql server 2000. i read this article (http://forums.asp.net/thread/1538777.aspx), but was not able to adapt it to what i am doing.
i am open to other suggestions of how to do this if you know of a cleaner or more efficient way. thanks!

View 2 Replies View Related

How To Update Selected Columns Of A Table In SQL Server Db Using Data From A Excel File?

Apr 4, 2007

Hi,I have an Excel file with 400 rows of old values and the correspondingnew values. My table currently has 10 columns out of which 3 columnsuse the old value specified in the excel file. I need to update thoseold values in the columns with the new values from the Excel file.Please guide me as to how to proceed with this.Thanks in advance!

View 4 Replies View Related

SQL 2012 :: Query To Make Single Records From Multiple Records Based On Different Fields Of Different Records?

Mar 20, 2014

writing the query for the following, I need to collapse the continuity. If the termdate for an ID is one day less than the effdate of the next id (for the same ID) i need to collapse the records. See below example .....how should i write the query which will give me the desired output. i.e., get min(effdate) and max(termdate) if termdate is one day less than the effdate of next record.

ID effdate termdate
556868 1999-01-01 1999-06-30
556868 1999-07-01 1999-10-31
556869 2002-10-01 2004-01-31
556872 1999-02-01 2000-08-31
556872 2000-11-01 2004-01-31
556872 2004-02-01 2004-02-29

output should be ......

ID effdate termdate
556868 1999-01-01 1999-10-31
556869 2002-10-01 2004-01-31
556872 1999-02-01 2000-08-31
556872 2000-11-01 2004-02-29

View 0 Replies View Related

Reporting Services :: How To Display (All Selected) When Parameter (Select All) Is Selected In SSRS

May 6, 2015

Using SSRS 2008 r2...I have a report with a single-value parameter and three multi-value parameters, Class1, Name2 and Name3. I'm hoping for an explanation to one thing that I'm seeing and information on a second thing.

Class1 and Name2 both have the (Select All) parameter selected but Class1 is displaying the concatenated parameter variable list whereas Name2 is showing Null. Why is that? If anything, how can I get Class1 to be similar to Name2 and show Null?But my desired wish is to have Class1, Name2 and Name3 display the text"All Selected" when the parameter (Select All) is chosen.

View 3 Replies View Related

SQL 2012 :: Selected Subscriber Does Not Satisfy Minimum Version Compatibility Level Of Selected Publication

Feb 21, 2014

I have created a Transactional Replication Publication on my SQL 2012 server.When I log into another server on the domain running 2008R2 and try to subscribe to the 2012 Publication, I get the following error when clicking on "Add SQL Server Subscriber": "The selected Subscriber does not satisfy the minimum version compatibility level of the selected publication"

The 2012 DB is set as 2008 Compatibility Mode?Am I not able to Publish from 2012 to 2008?.I was using SSMS 2008 to connect to my 2012 Instance, thats why it didn't work...

View 0 Replies View Related

I Want To Transfer ONLY New Records AND Update Any Modified Records From Oracle Into SQL Server Using DTS

Jul 23, 2005

I need a little help here..I want to transfer ONLY new records AND update any modified recordsfrom Oracle into SQL Server using DTS. How should I go about it?a) how do I use global variable to get max date.Where and what DTS task should I use to complete the job? Data DrivenQuery? Transform data task? How ? can u give me samples. Perhaps youcan email me the Demo Package as well.b) so far, what I did was,- I have datemodified field in my Oracle table so that I can comparewith datelastrun of my DTS package to get new records- records in Oracle having datemodified >Max(datelastrun), and transferto SQL Server table.Now, I am stuck as to where should I proceed - how can I transfer theserecords?Hope u can give me some lights. Thank you in advance.

View 2 Replies View Related

Can A Query Using OUTPUT Statement Be SELECTED From?

Oct 19, 2007

I tried wrapping a DELETE FROM ...OUTPUT DELETED.* WHERE... inside of a select, crossed my fingers and got a syntax error. I thought maybe since the OUTPUT statement produces a rowset that it and it's DELETE could be selected from. Is such a thing possible in the same query or should I give up?

View 5 Replies View Related

Dataset MDX Query For ALL Selected In Parameters

Apr 2, 2008



Hello All,

I have 2 MultiValued Parameters in my reports, our of which first is dependent on the other.

Eg. I have a SubProductGroup Parameter and depending upon the value selected in SubProductGroup, the other parameter which is Product gets filled in combo box.

Both these parameters are MultiValued and I am having "Select ALL" option in both the combo box.

Now, whenever you select any SubProductGroup values, the Dataset for Product gets executed to fill the Product combo box.

The MultiValued Parameters works using the "IN" Clause. All those products are retrieved which are "IN" the selected SubProductGroup.

Whenever user selects "Select All" option for SubProductGroup, there is no need for this "IN" clause, because we actually need all the records for Product.

Similarly, I have the Main Dataset which retrieves the Sales data for the Products selected from the Combo Box. So, the same question arises there also.

Right now I am using STRTOSET( ) and Join( ) function and this is working fine for me.

But when User Selects "Select All" in SubProductGroup, it takes a long time to fill the combo box for Product as well as when user selects "Select All" for Product, it takes a long time for the actual Dataset to retrieve records. But its working fine.

In order to improve the Performance, I am trying to eliminate this IN clause when "Select All" is selected.

How can I do this ?


Any Inputs ?

Thanks & Regards,
Kapadia Shalin P.

View 4 Replies View Related

SQL Query - Updating Selected Rows/Creating New Row - Same Table

Jan 24, 2008

I have to write a couple scripts that will update a couple columns in two separate tables and also insert a new row with the same data except for a few calculated or provided values ...... see specs below ...




1. tGradeHist Table Script One (Needs to be run first)



a. Read tGradeHist Table and Select rows with GradeEndDate = NULL and GradeStartDate = '1/1/2007 12:00:00 A.M.'

b. Calculate New Step Amount = StepAmount * Incr% (Round To Nearest Whole Dollar)

c. Create New Row for this table using information from row read above and insert new information where indicated :


GradeCode - Same

GradeLocationCode - Same

Step - Same

GradeStartDate - '7/1/2007 12:00:00 A.M.'

GradeEndDate - NULL

GradeCurrencyCode - Same

StepAmount - Result of b (above)

GradeFrequencyCode - Same

RangeMaximumAmount - Same

RangeMidAmount - Same

RangeMinimumAmount - Same

GradeCurrentFlag - 'True'

MarketMaximumAmount - Same

MarketMidAmount - Same

MarketMinimumAmount - Same

GradeGUID - Same

TSCOL - Same


d. Update Row read in a (above) with GradeEndDate = '6/30/2007 12:00:00 A.M.' and GradeCurrentFlag = 'False'





2. tPersonBasePayHist Table Script Two (Needs to be run second)


a. Read tPersonBasePayHist Table and Select rows with PersonBasePayEndDate = NULL

b. Calculate New PersonBasePayAmount = PersonBasePayAmount * Incr% (Round To Nearest Whole Dollar)

c. Create New Row for this table using information from row read above and insert new information where indicated :



PersonGUID - Same

PersonBasePayStartDate - '7/1/2007 12:00:00 A.M.'

PersonBasePayEndDate - NULL

PersonBasePayCurrencyCode - Same

PersonBasePayAmount - Result of b (above)

PersonBasePayFrequency - Same

PersonBasePayPayrollFrequencyCode - Same

BasePayReasonCode - 'SA'

ConductedBasePayReviewDate - Same

ScheduledBasePayReviewDate - Same

PayrollCode - Same

PersonBasePayCurrentFlag - 'True'

ApprovedByPersonGUID - Same

PersonBasePayGUID - Same

TSCol - Same



d. Update Row read in a (above) with PersonBasePayEndDate = '6/30/2007 12:00:00 A.M.' and PersonBasePayCurrentFlag = 'False'














View 7 Replies View Related

Sql Query To Retrieve Comments Based On Selected Month And Data

Jan 4, 2008

hi,
i am generating report for my project.
my table goes like
ID   VASID     VASSID     JanMail   JanVisit    JanPhone    JanComment    FebMail   FebVisit    FebPhone   FebComment................. DecPhone  
1      25            4              True         False         False            Mail me             False       True           False            Visit me                  
 
My report has 3 check boxes for Mail,Visit,Phone respectively and a listbox of 12 months january-december respectively.. 
once user check on Mail and select a month suppose January in my report,the report should generate only January Comments.
here user can select any number of months.if user selects january,february and march, report should generate respective months Comments.
Please help me in writing SQL Query to get the comments.......
 
if any one know the solution for the above problem,Please help me
 
Thanks & Regards,
 

View 2 Replies View Related

Need Efficient Query To Partition Records By Type And Pull Top N Records From DB

Jan 18, 2008

I have a query similar to the following. The intent of this query is to retrieve the top 6 records meeting the specified criteria (LOGTYPENAME = 'Process Status Start' OR LOGTYPENAME = 'Process Status End' ) based on most recent dates. Please keep in mind that I expect to return up to 6 records for each unique LogProcessName. This could be thousands of different LogProcessNames with up to 6 records for each.

1) The table I am executing against currently is very large in size and thus takes a long time to execute against. It would seem there must be a more efficient query to get the results I am looking for?
2) CTE doesn't work on SQL 2000. I need a query that does.
3) I cannot modify the database itself in the process.


;WITH cte AS (
SELECT [LogProcessName], [LogBody], [LogDate], [LogGUID], row_number()
OVER(PARTITION BY [LogProcessName]
ORDER BY [LogDate] DESC)
AS RN
FROM [LOGTABLE]
WHERE [LogTypeGUID] IN (
SELECT LogTypeGUID
FROM LOGTYPE
WHERE LogTypeName = 'Process Status Start'
OR LogTypeName = 'Process Status End' ) )
SELECT *
FROM cte
WHERE RN = 1 OR RN = 2 OR RN = 3 OR RN = 4 OR RN = 5 OR RN = 6
ORDER BY [LogProcessName] DESC, [LogDate] DESC

Does anybody else have any idea that would yield the results that I am looking for and take into account items 1-3 above?

Thanks in advance.

View 4 Replies View Related

Update Records

Aug 15, 2007

Here is my question if anyone can help...

I have two tables

Table 1

EmpName
PolicyNumber

Table 2

EmpName
PolicyNumber
NewEmpName

I would like to update Table 1 with the data from Table 2. Here is my problem..Lets say that I have two records in Table 2 that have the same policyNumber but two different NewEmpNames, it only takes the first. In other words, a single policynumber can be moved to a New EmpName and then again later on to another NewEmpName adn even again if need be

Any help is greatly appreciated.

-Matt




View 1 Replies View Related

Update Of Records From Other Tables

Sep 11, 2000

I am trying to update a field within one table with the values from another table. With the criteria that another field in each table are equal. What is the correct way to do this. My syntax is all wrong.

thanks
Jason

View 1 Replies View Related

Update Child Records Help

Oct 5, 2004

Please help

I have table1 which has many unique ID numbers and table2 that has many records for each ID. some of the ID numbers in table1 have changed and I have created a translation table (table3) that links the old and new ID numbers.

What I need to do is some sort of update sql statement that updates all the records in table2 changing all the oldID numbers to the new ones using the translation table.

Table1 and table2 are not linked...can anyone help me with the sql statement

example

Table 1
IDNUM NAME
12345 Joe
12346 Mary
12347 David

Table2
IDNUM FIELD1
12345 hello
12345 goodbye
12346 hello
12347 goodbye
12346 hello
12346 goodbye

Table3
OLDID NEW ID
12345 54321
12347 74321

need to change the IDNUM in Table2 to 54321 where IDNUM = 12345 and same with 12347..Need to do this for many many IDs but not all.

Thanks very much

View 1 Replies View Related

Insert And Update Records

Feb 4, 2008

Good day to all, I am new here so i hope i am doing things correctly.

The Company i work for make coils of shaped wire and work a 6 - 6 shift pattern

I have a database that is updated from a data collection source (MS Access) at 06:00 every morning. This seems to be working ok, my problem is that most coils fit nicely into the 6 - 6 shift pattern, but some now and again drift over into the next shift. I have written a crystal report that picks up this data. at the moment the coils are put in the database as: [Coil Start Time], [Coil Finish Time], [Coil Start Weight], [Coil Finish Weight], etc.

I have written (been helped to write) a SQL statement that will do the following:

Step 1: If the Coil Finish time is greater than the shift end time, then set the shit end time to be coil end time and zero start and finish wheight.
Step 2: The original Coil record is duplicated and Coil Start time set to start time of shift, all other data left alone.

Example of code:

-->>

SELECT [Batch Name], [Batch Start], [Batch End], [Coil Start Weight], [Coil Finish Weight], [Product], [Shift], [Operator ID], [Works Order No]
FROM dbo.tblCoilData
WHERE (DATEPART(hour, [Batch Start]) >= 6 AND DATEPART(hour, [Batch End]) < 18) OR
((DATEPART(hour, [Batch Start]) < 6 OR
DATEPART(hour, [Batch Start]) >= 18) AND (DATEPART(hour, [Batch End]) < 6 OR
DATEPART(hour, [Batch End]) >= 18))
UNION ALL
SELECT [Batch Name], [Batch Start], DATEADD(hour, 17, DATEADD(minute, 59, CONVERT(char(10), [Batch End], 101))), 0, 0, [Product], [Shift], [Operator ID],
[Works Order No]
FROM dbo.tblCoilData
WHERE DATEPART(hour, [Batch Start]) >= 6 AND DATEPART(hour, [Batch Start]) < 18 AND (DATEPART(hour, [Batch End]) < 6 OR
DATEPART(hour, [Batch End]) >= 18)
UNION ALL
SELECT [Batch Name], DATEADD(hour, 18, CONVERT(char(10), [Batch Start], 101)), [Batch End], [Coil Start Weight], [Coil Finish Weight], [Product], [Shift],
[Operator ID], [Works Order No]
FROM dbo.tblCoilData
WHERE DATEPART(hour, [Batch Start]) >= 6 AND DATEPART(hour, [Batch Start]) < 18 AND (DATEPART(hour, [Batch End]) < 6 OR
DATEPART(hour, [Batch End]) >= 18)
UNION ALL
SELECT [Batch Name], [Batch Start], DATEADD(hour, 5, DATEADD(minute, 59, CONVERT(char(10), [Batch End], 101))), 0, 0, [Product], [Shift], [Operator ID],
[Works Order No]
FROM dbo.tblCoilData
WHERE (DATEPART(hour, [Batch Start]) < 6 OR
DATEPART(hour, [Batch Start]) >= 18) AND DATEPART(hour, [Batch End]) >= 6 AND DATEPART(hour, [Batch End]) < 18
UNION ALL
SELECT [Batch Name], DATEADD(hour, 6, CONVERT(char(10), [Batch Start], 101)), [Batch End], [Coil Start Weight], [Coil Finish Weight], [Product], [Shift],
[Operator ID], [Works Order No]
FROM dbo.tblCoilData
WHERE (DATEPART(hour, [Batch Start]) < 6 OR
DATEPART(hour, [Batch Start]) >= 18) AND DATEPART(hour, [Batch End]) >= 6 AND DATEPART(hour, [Batch End]) < 18

<<--

I have 2 options now

option 1:
Leave this as a SQL View and report from this

option 2:
Insert updated records to the tblCoilData table so that the data in the table is permanent

I would prefer option 2 but am a bit of a nugget when it comes to writing update / insert statements, Could someone please help me with this

Thank you very kindly


Regards

Steve Dyson

View 4 Replies View Related

Update On Mulitple Records

Feb 17, 2004

I Have three tables

TASK
taskid, taskname, projectid, workid
1,,1,1
2,,1,2
3,,2,3

PROJECT
projectid, projectname
1, project1
2, project2
3, project3

WORK
workid, workname
1,work1
2,work2
3,work3

I need to do an update this way

Update the taskname as 'projectname' + '_' + 'workname' for any projectid.
projectname and workname coming from the projectid and workid in the task record

so the task table becomes
1,project1_work1,1,1
2,project1_work2,1,2
3,project2_work3,2,3

I can get all the records doing this

SELECT p.projectname+ ' ' + w.workname AS 'NEWNAME'
FROM task t
JOIN work w
ON t.workid = w.workid
JOIN project p
ON t.projectid = p.projectid
WHERE projectid = 2

how do i do an UPDATE?

any help is appreciated

View 2 Replies View Related

How To Update 2 Records On 1 Field

Aug 20, 2013

I have this code

I want to update nilai = total where kd_bulan = 9 and nilai = 0 where kd_bulan = 12

View 13 Replies View Related

Update Top 25 Records In Table

Sep 23, 2013

I'm having a problem with the syntax for doing an update to the top 25 records in my table.... This is what i have...

UPDATE TOP (25) FROM ud402.jd_mcp_master SET comments = 'MONDAY 092313 ' WHERE QUEUE_NAME = 'JD_Testing' ORDER BY DATE_WORKED ;

View 8 Replies View Related

What To Update The Duplicate Records

Jul 11, 2007

hi,

i want to update the second row of the c column.can any one help me in this . this is the sample records.
a b c
001testNULL
001testNULL
005testNULL

View 16 Replies View Related

Update Take Too Long On Some Records.

Mar 31, 2008

Hi all,

I have confusing problem here. My table which have about 150.000 rows have problem with updates on 15 rows.

It's access application which connect to sql server 2005 database. Access gets error:
"ODBC --update on linked table 'MyTable2 failed"

If i try to update on sql it's take couple minutes to update.
Evrything else on that table is ok.

View 11 Replies View Related

How To Do An Update On Existing Records?

Jul 20, 2005

I have one table of new records (tableA) that may already exist intableB. I want to insert these records into tableB with insert if theydon't already exist, or update any existing ones with new data if theydo already exist. A column (Action) in tableA already tells me whetherthis is an INSERT, UPDATE, or DELETE. I'm able to derive that I can doan insert withselect * into tableB from tableA where Action = 'INSERT'....and I think I can handle the delete.But I'm stuck on the update. How do I do the update? An ordinaryUPDATE statement just won't do unless I use a cursor to cycle throughthe recordset. I want to avoid a cursor.

View 1 Replies View Related

Use Db-lib To Update Database Records

Jul 20, 2005

How to use db-lib to update/insert database records without using SQLlanguage. I want to change the value of the data individually withoutplugging in the new values in the SQL language then execute it. Theperfect situation for me is loop through the retrieved records thenedit the values individually until EOF.Thanks,Carlo

View 1 Replies View Related

Update ID Field Of All Records

Aug 29, 2007

Hi everyone,

I'm fairly basic in SQL and I was wondering if it was possible to update the id field of a certain table in all records of that table. And to update the links to those ids in other tables.


Hope you understand and thanks in advance,
Tobias

View 12 Replies View Related

All The Records Update Or Just Half?

May 26, 2008

update top (50) percent table1 set fields1 = 1
update top (50) percent table1 set fields1 = 2

like the subject, all or half? thanks

View 6 Replies View Related

Update Table From Old Records

Apr 23, 2008



I'm using SQL Server 2000.

I have a table with data similar to this.... Multi field = 0 indicates current record, 1 indicates an old record

FWK NVQ Multi Key Start Date NVQ Date FWK Date
NULL NULL 0 123456 03/04/2006 NULL NULL
NULL NULL 1 123456 03/04/2005 01/09/2006 NULL
NULL NULL 0 234567 03/04/2006 NULL NULL
NULL NULL 1 234567 03/06/2005 04/10/2005 03/11/2005
NULL NULL 0 345678 03/04/2004 NULL NULL
NULL NULL 1 345678 03/07/2003 NULL 01/12/2003
NULL NULL 1 345678 03/08/2002 NULL NULL
NULL NULL 0 456789 30/09/2002 11/06/2003 NULL
NULL NULL 1 456789 29/08/2000 NULL NULL
NULL NULL 0 567890 30/09/2002 11/06/2003 11/06/2003
NULL NULL 1 567890 29/08/2000 30/05/2001 NULL
NULL NULL 0 678901 03/04/2006 01/09/2006 15/09/2006
NULL NULL 1 678901 30/03/2005 30/08/2005 15/08/2005
NULL NULL 0 789012 02/03/2000 03/09/2000 15/09/2000
NULL NULL 0 789013 30/06/2001 07/08/2001 14/08/2001


I need to update the table, setting the first two columns to the date of the old records... ie. I want the table to look like this...

FWK NVQ Multi Key Start Date NVQ Date FWK Date
NULL 01/09/2006 0 123456 03/04/2006 NULL NULL
NULL NULL 1 123456 03/04/2005 01/09/2006 NULL
03/11/2005 04/10/2005 0 234567 03/04/2006 NULL NULL
NULL NULL 1 234567 03/06/2005 04/10/2005 03/11/2005
01/12/2003 NULL 0 345678 03/04/2004 NULL NULL
NULL NULL 1 345678 03/07/2003 NULL 01/12/2003
NULL NULL 1 345678 03/08/2002 NULL NULL
NULL NULL 0 456789 30/09/2002 11/06/2003 NULL
NULL NULL 1 456789 29/08/2000 NULL NULL
NULL 30/05/2001 0 567890 30/09/2002 11/06/2003 11/06/2003
NULL NULL 1 567890 29/08/2000 30/05/2001 NULL
15/08/2005 30/08/2005 0 678901 03/04/2006 01/09/2006 15/09/2006
NULL NULL 1 678901 30/03/2005 30/08/2005 15/08/2005
NULL NULL 0 789012 02/03/2000 03/09/2000 15/09/2000
NULL NULL 0 789013 30/06/2001 07/08/2001 14/08/2001


Can anyone help me with this?
Jon




Code Snippet
DECLARE @TABLE_JR TABLE
([FWK] datetime,
[NVQ] datetime,
[Multi] Smallint,
[Key] varchar(10),
[Start Date] datetime,
[NVQ Date] datetime,
[FWK Date] datetime)
INSERT INTO @TABLE_JR VALUES (null,null,0,'123456','2006-04-03',null,null)
INSERT INTO @TABLE_JR VALUES (null,null,1,'123456','2005-04-03','2006-09-01',null)
INSERT INTO @TABLE_JR VALUES (null,null,0,'234567','2006-04-03',null,null)
INSERT INTO @TABLE_JR VALUES (null,null,1,'234567','2005-06-03','2005-10-04','2005-11-03')
INSERT INTO @TABLE_JR VALUES (null,null,0,'345678','2004-04-03',null,null )
INSERT INTO @TABLE_JR VALUES (null,null,1,'345678','2003-07-03',null,'2003-12-01' )
INSERT INTO @TABLE_JR VALUES (null,null,1,'345678','2002-08-03',null,null )
INSERT INTO @TABLE_JR VALUES (null,null,0,'456789','2002-09-30','2003-06-11',null)
INSERT INTO @TABLE_JR VALUES (null,null,1,'456789','2000-08-29',null,null)
INSERT INTO @TABLE_JR VALUES (null,null,0,'567890','2002-09-30','2003-06-11','2003-06-11')
INSERT INTO @TABLE_JR VALUES (null,null,1,'567890','2000-08-29','2001-05-30',null)
INSERT INTO @TABLE_JR VALUES (null,null,0,'678901','2006-04-03','2006-09-01','2006-09-15')
INSERT INTO @TABLE_JR VALUES (null,null,1,'678901','2005-03-30','2005-08-30','2005-08-15')
INSERT INTO @TABLE_JR VALUES (null,null,0,'789012','2000-03-02','2000-09-03','2000-09-15')
INSERT INTO @TABLE_JR VALUES (null,null,0,'789013','2001-06-30','2001-08-07','2001-08-14')

View 7 Replies View Related







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