Single Query To Update And Append

May 5, 2004

I need to write a single query that will append the values from one table into another table but I need to update a single field in the table with a static value. What I'm working with is an Access .adp with an SQL 2000 backend. The database is used to track ticket sales, payments, and contact info for season ticket holders. Prior to upsizing, each year the database would be copied and then choice bits modified for the next year.

In other words, the history was in several databases, i.e. db2001, db2002, db2003 and for the current year dbcurrent. I decided to create a historic tables in the current DB rather than have umpteen DBs on my SQL server.

My problem is that I need to create a query that appends to my table the previous years data and then updates the season field to reflect the season that the data came from.

In short, say I have a table named accounts
with fields
account, customer, addr1, addr2, ..., ticket type
and I want it to end up in
account_hist with fields
account, customer, addr1, addr2, ..., ticket type, SEASON
and make the season equal say 8 which represents the 8th season the team has played.
I can get both queries to work seperately :D , but for end user ease, I want to perform both actions at the same time :confused: .
Can anybody point me in the right direction?
Thanks

View 2 Replies


ADVERTISEMENT

Single Update Query

Apr 29, 2008

Table Name:-emp
table structure:-  Name           Gender
                         A                  Male
                         B                  Male
                         C                  FeMale
                         D                  FeMale
I want only one update query to update this table like this
table structure:- Name           Gender
                         A                  FeMale
                         B                  FeMale
                         C                  Male
                         D                  Male
   please help me?                  

View 1 Replies View Related

Can I Update Two Tables In A Single Query

Jun 14, 2008

hi friends

in my sqlserver 2005 i want to update two tables in a single query.

is it possible? or is it possible by creating a view?

thanks in advance.

shweta

View 3 Replies View Related

Single Update Query Using In Clause In SP

Jan 4, 2008

Hello,

I'm collecting id based on user's selection and storing to ArrayList/String[in asp.net]. Now want to pass those ids stored to stroed procedure. I want SP to update all records in single statement using in like update table set field in (value).

I'm storing id with comma (,) separator. Below is my asp.net code:


string sId=string.Empty;

for(int a=0;a<Id.Count;a++)

{

Id += Id;

if(a!=Id.Count-1)

sId +=",";

}

In database id column is int type. I'm passing id collected with comma separator and passing it as a parameter to SP. but it is giving error related converting to int or similar.

Plz help me create Stored Procedure in SQL 2005 based on above scenario.

Thanks

View 7 Replies View Related

Update Multiple Rows In A Single Query?

Jul 30, 2007

I know this isn't right but I'm trying to build a single query in PHP to re write the sortorder column starting at 0 and writing every row in order.



Code:


update categories set (sortorder=0 where catid=32), (sortorder=1 where catid=33),(sortorder=2 where catid=36) where userid=111




PHP Code:




 $qt="update categories set ";
for($i=0;$i<$num;$i++){
    $a=$i+1;
    $qt.="sortorder=$i";
    if($a<$num){
        $qt.=", ";
    }
}
$qt.=" where userid=111"; 





Using PHP I can amend the loop above to slot in a row I want so I can change the sort order.

unfortunately I'm not sure how to build such a query in mssql, can anyone help?

View 5 Replies View Related

Update Multiple Tables In Single Query

Apr 3, 2008

Hello All,

I want to update multiple tables using single query and fields name are same of tables.
I am trying like:

update tablename1 t1,tablename2 t2 set t1.fieldname1 = t2.fieldname1 = 'value' where condition;

or

update tablename1 t1,tablename2 t2 set t1.fieldname1 = 'value' t2.fieldname1 = value where condition;

Plzzzzzz help me.Thanx in advance.


Thanx & Regards,
Smita.

View 17 Replies View Related

Update Multiple Tables Using A Single Query

Nov 6, 2007

Hi,
I am using SQl server 2005.
want to update rows in 2 tables,which have a relation on Id field.

Some thing like
Update tblA a , tblB b
Set a.UpdatedDt=getdate(),b.Updateddt=getdate()
where a.Id=b.Id and a.Name='xyz'

can anyone out there help me?


Thanks
Renu

View 2 Replies View Related

Single Query - Update Same Column In Diff Table

Sep 25, 2014

I have two tables table1 and table2 and having a common column "col1"

When i ran the following query

UPDATE table1, table2 SET col1=FALSE WHERE id = 1;

getting the following error

Error Code: 1052
Column 'col1' in field list is ambiguous

id column exist in both the tables and need to update both the tables to false where the id is equivalent to 1.

View 3 Replies View Related

SQL 2012 :: Single Query To Update Same Column Name In Different Tables With Where Condition?

Sep 25, 2014

I have two tables table1 and table2 and having a common column "col1"

When i ran the following query

UPDATE table1, table2 SET col1=FALSE WHERE id = 1;

getting the following error

Error Code: 1052 Column 'col1' in field list is ambiguous

id column exist in both the tables and need to update both the tables to false where the id is equivalent to 1.

how to achieve this in single query?

View 4 Replies View Related

DTS Append And Update

Jul 5, 2001

I need to copy data from one SQL table to another SQL table. Is is possible to use DTS to Append and update data from one table to another....along the line of using a Microsoft Access append or update query?

View 1 Replies View Related

Update Versus Append

Jul 23, 2005

I have a database that is being used as sort of a reports datawarehouse. I use DTS packages to upload data from all the differentsources. Right now I have it truncating the tables and appending withfresh data. I was considering using updates instead and my question waswhich is more efficent?

View 3 Replies View Related

Basic Table Update/append Question

May 12, 2004

I'm new to SQL server. I want to add or append a unique set of rows to a destination table from a source table, they are essentially the same table by definition. The source table is updated every hour via DTS, all rows deleted and new set added. Both tables have the same primary key. Approximately 40 unique rows are created each hour and I would think the best approach would be to append the new rows to the destination table. I think an Append query will run into a primary key conflict.

In Access, I did this within VB by checking the max value of the primary key and then running the append for any values greater than that.

In SQL, I'm not sure if this should be done as a stored procedure or if there is an easier approach altogether.

View 2 Replies View Related

Table Copy/Append/Update Question

Feb 23, 2008

I have a series of .csv files created by a parts system. The .csv filename is in the format partnumber.csv The csv file contains a date column and 6 other fields. Each csv file is about 4000 records and there are approx 7000 .csv files that get re-generated once a week.

I'm using c# SqlBulkCopy object to import the csv file into a temp table. No problem there. It works realy fast.

What I need now is a way to move the data from the temp table to the final table and append the partnumber. I'm thinking it would be easy to pass the partnumber in as a paramerter to a t-sql query but not sure how to write the query itself.
I also want to check if the partnuber/datestamp combination from the temp table already exists in the final table and skip it if it does. So I suppose I ultimately need an update query.

Once I have that query written it's easy to import a .csv, launch the update query, wipe the temp table and repeat with the next .csv file.

Temp Table Layout: DateStamp(datetime), Field1 ... Field6(all real's)
Final Table Layout: PartNumber(varchar), DateStamp(datetime), Field1 ... Field6(all real's)


TIA.

View 4 Replies View Related

SQL Server 2000 - Issue W/ UPDATE - Single Row Update Returns 2 Different Messages

Nov 11, 2007

I am hoping someone can shed light on this odd behavior I am seeing running a simple UPDATE statement on a table in SQL Server 2000.  I have 2 tables - call them Table1 and Table2 for now (among many) that need to have certain columns updated as part of a single transaction process.   Each of the tables has many columns. I have purposely limited the target column for updating to only ONE of the columns in trying to isolate the issue.  In one case the UPDATE runs fine against Table1... at runtime in code and as a manual query when run in QueryAnalyzer or in the Query window of SSManagementStudio - either way it works fine. 
However, when I run the UPDATE statement against Table2 - at runtime I get rowsaffected = 0 which of course forces the code to throw an Exception (logically).  When I take out the SQL stmt and run it manually in Query Analyzer, it runs BUT this is the output seen in the results pane...
(0 row(s) affected)
(1 row(s) affected)
How does on get 2 answers for one query like this...I have never seen such behavior and it is a real frustration ... makes no sense.  There is only ONE row in the table that contains the key field passed in and it is the same key field value on the other table Table1 where the SQL returns only ONE message (the one you expect)
(1 row(s) affected)
If anyone has any ideas where to look next, I'd appreciate it.
Thanks 
 

View 2 Replies View Related

Plz Help...update Value In Multiple Db Table Using Single 'update Command'

Mar 18, 2005

hi,friends

we show record from multiple table using single 'selectcommand'.
like....
---------
select *
from cust_detail,vend_detail
---------

i want to insert value in multiple database table(more than one) using single 'insert command'.
is it possible?
give any idea or solution.

i want to update value in multiple database table(more than one) using single 'update command'

i want to delete value in multiple database table(more than one) using singl 'delete command'
it is possible?
give any idea or solution.

it's urgent.

thanks in advance.

View 2 Replies View Related

Help With Access Append Query To Ms Sql

Feb 21, 2006

hi,
I am in the process of creating an append query that sends the fields of an open form from my ms access 2000 db to a table in ms sql 2000. I've successfully linked the ms sql tables and created the query to pull data from my form but when i run the append i get a key violation error and nothing gets appended. I know which field is the primary key in ms sql i just don't know how to change my access table to suit, any ideas?

To start I've made my append query simple and it just pulls the contact name. Here's my sql statement if that helps.
CODE
INSERT INTO dbo_PatientMaster ( PatientFirstName, PatientLastName, PatientAccountNumber )
SELECT [Forms]![Contacts]![FirstName] AS Firstname, [Forms]![Contacts]![LastName] AS [Last], [Contacts]![PatientAccountNumber] AS [Patient Account Number]
FROM Contacts, dbo_PatientMaster
GROUP BY [Forms]![Contacts]![FirstName], [Forms]![Contacts]![LastName], [Contacts]![PatientAccountNumber];
In access the patient account number is empty and I just created that field in my access table today.

thanks in advance

View 6 Replies View Related

Append Query Problems

Nov 30, 2006

Hi

I am doing an A level database project. I need to build a system to deal with ordering and selling products.

I am trying to make an append query that will append all the products bought in my "invoices" table to my "archive" table. I want invoices that are three months old to be transferred the the "archive" table. I have been trying to put a criteria in the query for the Date field but I haven't managed to find an expression that works.

I'm sorry if this is too simple and you guys think im just being stupid.
I figured it was worth asking on here!! It's really bugging me.

View 6 Replies View Related

Append Query Problem

Jul 20, 2005

I'm testing this query and it does not append any new rows from thesource tables unless the destination table is empty. I want to designthe query just to add new records from the destination tables and leaveexisting ones in tact. Help appreciated. Query:INSERT INTO tMASmembers ( Division, CustomerNumber, CustomerName,AddressLine1, SalesPersonCode, SIC_Code, SIC_Desc )SELECT AR1_CustomerMaster.Division, AR1_CustomerMaster.CustomerNumber,AR1_CustomerMaster.CustomerName, AR1_CustomerMaster.AddressLine1,AR1_CustomerMaster.SalesPersonCode, AR_90_UDF_AR_Customer.Sic_Code,AR_90_UDF_AR_Customer.Sic_DescFROM AR1_CustomerMaster INNER JOIN AR_90_UDF_AR_Customer ON(AR1_CustomerMaster.Division = AR_90_UDF_AR_Customer.Division) AND(AR1_CustomerMaster.CustomerNumber =AR_90_UDF_AR_Customer.CustomerNumber)WHERE (((AR1_CustomerMaster.Division) Not In (Select[tMASmembers].[Division] From [tMASmembers])) AND((AR1_CustomerMaster.CustomerNumber) Not In (Select[tMASmembers].[CustomerNumber] From [tMASmembers])) AND((AR1_CustomerMaster.CustomerName) Not In (Select[tMASmembers].[CustomerName] From [tMASmembers])) AND((AR1_CustomerMaster.AddressLine1) Not In (Select[tMASmembers].[AddressLine1] From [tMASmembers])) AND((AR1_CustomerMaster.SalesPersonCode) Not In (Select[tMASmembers].[SalesPersonCode] From [tMASmembers])) AND((AR_90_UDF_AR_Customer.Sic_Code) Not In (Select[tMASmembers].[SIC_Code] From [tMASmembers])) AND((AR_90_UDF_AR_Customer.Sic_Desc) Not In (Select[tMASmembers].[SIC_Desc] From [tMASmembers])));*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 3 Replies View Related

Append Query With Isnull Function

May 21, 2004

i'm trying to run an append query using data from 2 tables. i want to replace nulls with blanks ('') bellow is my statment. when i run this statment with out the iif(isnull)) statmentes the query works fine. is there another way of replacing my nulls with blanks.
Thank you,
Thomas

insert into tblcustomers (cusName, cusNumber, Active, cusContact, cusCrLimit,cusTerms)
SELECT dbo.tblCustomersIOA.CustomerName, dbo.tblCustomersIOA.Cust#,
dbo.tblCustomersIOA.Active,
iif(isnull(dbo.tblCustomersIOA.Contact),'',dbo.tbl CustomersIOA.Contact) ,
dbo.tblCustomersIOA.CreditLimit,
FROM dbo.tblCustomerNotesIOA RIGHT OUTER JOIN
dbo.tblCustomersIOA LEFT OUTER JOIN
WHERE (dbo.tblCustomersIOA.CountryID = 1) AND (dbo.tblCustomersIOA.StateID = 2);

View 1 Replies View Related

SQL Query - Append Data From Two Tables

Jul 20, 2005

I need to run a query which will pull data from two tables and appendit as one when it displays the result. The data are in two tables. Butthe result set will be identical in terms of number of columns. I wantto display it one set below the other.This is for pay history. From 2003 we have a new payroll system. Till2002 we used to have a different system. But I need to run a querywhich will pull the data for an employee for the last one year. So theinformation is spread out between these two tables. Both these tablesare in SQL Server databases.I want to write a Stored Procedure. I can use Shape/Append but I thinkit doesnt work on QA/Stored Proc. It needs an OLEDB.How can I write the query. I dont want to use temporary tables and doinserts.ThanksGIRISH

View 1 Replies View Related

Backup Restoration / Append Query

Jul 20, 2005

Hi All:Being a bit of a nube to MSSQL I could use a little advice. This is thesituation.A client's HDD became full so I backed up, deleted then recreated a blankdatabase (they said they didn't need the stored data).They have now deceided that they want the data again.My plan is to restore the database to a second volume so it can grow as muchas is needed, however, there is now data in the second instance that wouldneed importing to the restored DB.I can restore the backed up db with a different name and reconfigure thesoftware that accesses it but what would be the best method to append therestored DB with the data in the current instance of said DB? Both DBs areidentical.TIAMP

View 1 Replies View Related

How Do I Append String To End Of Sql Query Results?

Jul 20, 2005

I need to append text to the end of my sql query results.For instance, my query returns a list of user names infirstname.lastname. I need to add @yahoo.com to each record. So theend result should be Join Bytes!. What should byselect statement look like?Any help?

View 2 Replies View Related

Append Query Problems, From Access To Excel

Feb 27, 2003

Hi everyone. I have a problem with an append query runing from a small Access database and would very much appreciate some input.

The append query from Access is as follows:

INSERT INTO TransferTable ( Name, Surname, Company, Address1, Address2, [Town/City], County, PostCode, Phone, Fax, Email, [Client type] )
SELECT [Clients].[Name], [Clients].[Surname], [Clients].[Company], [Clients].[Address 1], [Clients].[Address 2], [Clients].[Town/City], [Clients].[County], [Clients].[Post Code], [Clients].[PhoneNumber], [Clients].[FaxNumber], [Clients].[Email Address], [Clients].[ClientType]
FROM Clients
WHERE [Name]=[Forms]![Client Form]!Name;

This works up to a point. What it does is send the selected data to the TransferTable which is a link table to a sheet in an Excel workbook.

So far so good.

Each time the query is run though, it inserts the selectd data on the line below the previous run, even if the information that was inserted last time was not saved. So on the first run the query will drop the desired information into row A2 of the TransferTable, then even if that is deleted and the changes to the workbook are not saved, the next time the query is run it goes down to row A3, then A4 and so on. no doubt this is the exact point of an append query, but it's really aggravating me.

What I'd like is a query that will get the data into the same row of the TransferTable each time it is run, since another sheet in the Excel workbook runs some calculations based on the data held in the cells of the TransferTable sheet.

I've tried the SQL editor in Excel, but my very limited knowledge has left me completely frustrated. Does anyone have any ideas how I can achieve this outcome before I go completely nuts ?

I don't mind if the query runs from Excel or Access.

Thanks in advance to anyone who offers any input.

View 1 Replies View Related

MS Access Append Query To SQL Table Problem

Sep 22, 1998

Any known problems with using an Access Append query to add data to an SQL table?

View 1 Replies View Related

Firing An Append Query(stored Procedure) On The First Of Very Month

Mar 4, 2002

I need several stored procedures to fire on the 1st of every month. I was told my another developer I can possibly use SQL sever agent.

Any ideas????

View 1 Replies View Related

Server Trigger Timing Out Access Append Query

Oct 17, 2013

I have a SQL Server database running on a local PC which will eventually be scaled up once everything is working.

The Database takes data from an Access database, then the SQL Server aggregates this data into several other tables.

I have used a trigger to run this in SQL Server, once a table in SQL Server is appended with a specific value.

I have tested the trigger to do a simple task, and this works.

I have tested the aggregation query which create 18 seperate tables as well. It takes around 25 minutes to run. These are huge tables

When I use Access to append the final value to start the SQL Server trigger it freezes and eventually times out. I assume this is because it is running the 25minute trigger, and Access has to wait until this is completed before it can proceed.

I was hoping it would trigger SQL Server to run the trigger, then Access could go off and do something else!

View 10 Replies View Related

How To Update Single Column

Oct 25, 2007

hi guys i have a problem;;;

i have to update table'''


querey is--TABLE1 HAS A COLUMN CALLED CITY .THE RECORDS WITH CITY='DELHI' ARE IS TO BE UPDATED WITH CITY='MUMBAI' AND THE RECORDS WITH CITY='MUMBAI' ARE IS TO BE UPDATED WITH CITY='DELHI' ...

i HAVE TO WRITE A SINGLE SQLSTATEMENT TO DO THIS NOT WITH THE HELP OF CURSOR

View 14 Replies View Related

Single SP For Insert And Update

Apr 4, 2014

I Want to write a single SP which inserts and updates.

CREATE PROCEDURE sp_NewPassword
@UserName nvarchar(50),
@OldPassword nvarchar(50),
@NewPassword nvarchar(50)
AS
BEGIN
INSERT INTO RGH_ChangePassword(vUserName, vNewPassword) VALUES(@UserName, @NewPassword)
UPDATE RGH_LoginMaster SET vPassword=@NewPassword WHERE vUserName=@vUserName and vPassword=@OldPassword
END

When i tried to create above sp it gives me an error saying

Msg 137, Level 15, State 2, Procedure sp_NewPassword, Line 8
Must declare the scalar variable "@vUserName".

View 1 Replies View Related

Single SQL Update Statements

Oct 31, 2007


What is the single SQL statement to truncate the blank space on either side of data.
Ex.
Table1 has Name as column.
I have records filled with blank space on both side for Name field.
With one query I want to correct (truncate the leading and trailing space) the data.
How?
SQL Server 2005 SP2.
Thank you,
Smith

View 1 Replies View Related

Multiple SET/WHERE Within Single UPDATE?

Mar 21, 2008



Can an Update statement support multiple SET/WHERE clauses? The following example won't work, but this is what I'd like to be able to do:





Code Snippet
UPDATE [CPSAgacar].tmp_CTA2

SET [Admit Date] = NULL
WHERE [CPSAgacar].tmp_CTA2.CalcAdmitDate IS NOT NULL

SET CalcDischDate = Discharge
WHERE [CPSAgacar].tmp_CTA2.CalcAdmitDate IS NOT NULL AND CPSAgacar].tmp_CTA2.CalcDischDate IS NULL






Thanks.

View 1 Replies View Related

Update 2 Tables In Single Statement

Mar 13, 2008

Is it possible to update 2 tables in a single t-sql statement?

If Yes, whats the syntax?


Update Table1,Table2 ... is not working

View 2 Replies View Related

Single Statement For Insert Or Update

May 8, 2008

In VB6 using MDAC 2.8 I could do a single select statement that would act as either an Insert or an update. Is there a way to do this in ADO.net?
My old VB6 code
Dim dbData As New ADODB.Connection
Dim rs1 As New ADODB.Recordset
Dim strParm As String
Dim strCusNo As String
'
strParm = "Provider=SQLOLEDB; Data Source=SQL2000; Initial Catalog=DATA_01; User ID=UserName; Password=password"
dbData.Open strParm
'
strParm = "Select CusNo from CusFil Where CusNo = '" & strCusNo & "'"
rs1.Open strParm, dbData, adOpenStatic, adLockOptimistic, adCmdText
If rs1.BOF And rs1.EOF Then
rs1.AddNew
Else

End If
With rs1
!CusNo = strCusNo
.Update
End With
rs1.Close
'
Set rs1 = Nothing
dbData.Close
Set dbData = Nothing

Is there an ADO.Net equivalent?

thanks,

View 3 Replies View Related

Update Multiple Records From A Single ASP.NET Webpage

Mar 3, 2004

Got a beginner question here...
Let's say I have a database table that houses server information with four columns: make, model, serial #, ip address. And assume there are ten rows with that information filled out. How could I display all the rows of information on a single webpage (ASP.NET), with all the fields being editable; and a single save button that would send any changes to the database (in reality I guess it would be sending all rows and fields to the database, and just overwrite the previous data).

Could a page such as that be created using FrontPage 2003 or Dreamweaver MX 2004?

This would be strictly for updating information. I would have a separate form for adding a new entry.

Thanks for your help.

View 1 Replies View Related







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