Writing A Update To A Table With Data From Another Table.

Apr 24, 2008



Here is my current Query. (IT's Wrong!)
--------------------------------------------------

UPDATE tblMain

set Measure1 = (select measure1

from tblBulkDump

where tblMain.reportID = tblBulkDump.reportID),

Measure2 = (select measure2

from tblBulkDump

where tblMain.reportID = tblBulkDump.reportID),

DataLocation = (select DataLocation

from tblBulkDump

where tblMain.reportID = tblBulkDump.reportID),

BudgetSource = (select BudgetSource

from tblBulkDump

where tblMain.reportID = tblBulkDump.reportID),

Comments = (select Comments

from tblBulkDump

where tblMain.reportID = tblBulkDump.reportID)

--------------------------------------------------
I need to write an Update for the given fields from the tblBulkDump Tabble.

Thanks in advance,
Gene

View 1 Replies


ADVERTISEMENT

Writing Binary Data To A SQL Table (VB CODE)

Mar 9, 2006

First of all let me say that ASP.NET a new programming environment for me so please forgive my ignorance.
Can someone please tell me how to write data to a SQL table that is a Binary data type?  I have a stored procedure on the SQL server that I am calling to insert data into a table.  I build a parameter list and set the values.  It worked just fine before I added a binary field to the SQL table.  My problem is that I don't know how to set the Binay data type to pass it to the stored procedure.  Here is part of the code:
GetCMD = Myconnection.CreateCommand
GetCMD.CommandType = CommandType.StoredProcedure
GetCMD.CommandText = "SCHEMANAME.InsertLineItem"
GetCMD.Parameters.Add("HEADER_ID", SqlDbType.VarChar, 150)
GetCMD.Parameters("HEADER_ID").Value = "some value"
GetCMD.Parameters.Add("@OPTIONS", SqlDbType.Binary)
GetCMD.Parameters("@OPTIONS").Value =  HOW DO I SET THIS VALUE????
rowsaffected = GetCMD.ExecuteNonQuery()
I assume serialization but have not figured out how.  Anyone's help is greatly appreciated!!

View 1 Replies View Related

Transact SQL :: Update Table With Its Value And Data From Row In Temp Table For Matching Record?

Oct 25, 2015

I have a temp table like this

CREATE TABLE #Temp
 (
  ID int,
  Source varchar(50),
  Date datetime,
  CID varchar(50),
  Segments int,
  Air_Date datetime,

[code]....

Getting Error

Msg 102, Level 15, State 1, Procedure PublishToDestination, Line 34 Incorrect syntax near 'd'.

View 4 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 Multiple Table Referencing New Table Data

Aug 4, 2015

I have a table called ADSCHL which contains the school_code as Primary key and other two table as

RGDEGR(common field as SCHOOl_code) and RGENRl( Original_school_code) which are refrencing the ADSCHL. if a school_code will be updated both the table RGDEGR (school_code) and RGERNL ( original_schoolcode) has to be updated as well. I have been provided a new data that i have imported to SQL server using SSIS with table name as TESTCEP which has a column name school_code. I have been assigned a task to update the old school_code vale ( ADSCHL) with new school_code ( TESTCEP) and make sure the changes happen across all 3 tables.

I tried using Merge Update function not sure if this is going to work.

Update dbo.ADSCHL
SET dbo.ADSCHL.SCHOOL_CODE = FD.SCHOOL_Code
FROM dbo.ADSCHL AD
INNER JOIN TESTCEP FD
ON AD.SCHOOL_NAME = FD.School_Name

View 10 Replies View Related

Writing Data To OLEDb Dest With The Table Name Set Via A Variable. (ValidateExternalMetadata Issue)

Feb 16, 2007

 

I am using a foreach loop, with the data from an ado recordset, which contains the table name that I wish to write data to an OLEDB data dest.  The table names are retrieved from an execute sql task in the an object var.  Within the foreach loop, for each table name, I then use a datareader to an ado.net source to pull data from that table, via an expression construct into a variable - i.e. "select * from " + @[User::table_name].  This works fine for the first table, in which mappings are setup using the SSIS design environment.  The data is retrieved.  I then use a variable and set the data access mode for the oledb destination to "Table name or view name variable".  This also saves data fine for the first table in the loop in the oledb dest.  When the next table name is retrieved from the ado provider in the foreach loop, the datareader fails, as it still thinks the metadata mappings are from the first table, which was used for the mapping in the design environment.  I.E. FIN_CLASS is a column from the first table in the loop. 

Error: 0xC0202005 at Data Flow Task, DataReader Source [7181]: Column "FIN_CLASS" cannot be found at the datasource.

I have set the following properties, that I thought (in my feeble mind), are supposed to avoid that behavior.  For the datareader, I set ValidateExternalMetadata to false, and for the data flow task (container for the datareader), I set DelayValidation to true.  These settings, according to the doc, are supposed to evaluate metadata for the datareader source at runtime (not design time), so that the column metadata is dynamic, and so that the subsequent oledb destination can use the "data access mode" for the oledb destination of "Table name or view name variable".  

If I cannot get this to work, I have 2 options: Use OPENQUERY via dynamic t-sql statements, OR create 30 separate flows in SSIS - one for each table - not looking forward to that one.

View 5 Replies View Related

[Resolved] Update Table W. Data From Another Table

Jan 28, 2008

I have a sp where I have 2 tables. I have already populated ecah table with data.

Now I need to update Table1 with data from Table2.

Key fields between the 2 tables are job_date, job_number and job_phase.

If the record exists in Table1 (reading Table2) need to update record in Table1 with qty_received from Table2.

If record does not exists in Table1, need to insert record into Table1 with job_date, job_number, job_phase and qty_received from Table2

I am very new to sql and wonder if someone would be so kind to help me out? Thank you.


Table1 ie Target
job_date datetime,
job_number char(15),
job_phase char(15),
qty_delivered decimal(8,2)
qty_received decimal (8,2)

Table2 ie Source
job_date datetime,
job_number char(15),
job_phase char(15),
qty_received decimal(8,2)

View 8 Replies View Related

Update Table A With Data From Table B Without Specifying Every Column

Mar 25, 2008

hello all,

I don't know how to update table A with data from table B without specifying every column.
These two tables have the same fields and same structure.

I know that it's possible to do the following:

update table A

set A.name = B.name,

A.job = B.job
from table B

But I have many columns and don't want to describe every column, is that possible?

Thanks!

View 6 Replies View Related

Update Table With Data Calculated From The Same Table

Sep 21, 2007

Hello,

I'm attempting to explore the functionality of SSIS and all the available data flow transformations, and I'm trying to learn how to use the tool correctly.
How would someone update a table with data which is calculated from that same table.
This is a made up example. Lets say I have a table:


CREATE TABLE [dbo].[tst_source](

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

[object] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[color] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

[color_count] [int] NULL

)


I would like to populate the field color_count with the count of items listed with that color.

Data:
tst_key object color color_count
1, chair blue NULL
2, table black NULL
3 lamp black NULL
----
So the last column for 1st rec value would be 1, and for 2nd and 3rd, would be two.
tst_key object color color_count
1, chair blue 1
2, table black 2
3 lamp black 2

-- With T-SQL I would use the following code:

update tst_source

set color_count = res.cnt

from tst_source

Inner join (select count(tst_key) cnt,color

from tst_source

group by color) res

ON res.color = tst_source.color

But I would like to use the Data Transformations. Can someone explain in great detail which Data Transformation tasks I would need to use?

Thank you.

View 11 Replies View Related

Update Table With Data From Another Table

Jan 19, 2005

I have two tables ingram and ingram_update that have the identical fields. I need to update ingram with the content in ingram_update. How do I do this? Thank you for your help!

View 2 Replies View Related

How To UPDATE Table Using Data From Another Table

May 8, 2008

I have 2 tables...

Table1: FullName, City, State, Data1
Table 2: FullName, City, State, Data1, Data2, Data3

This is what I want to do...
1. For every record that is in BOTH tables I want to UPDATE TABLE 2 with the data from Table 1.
2. Then, if there are "extra"/new records in table 1 I want to append them to Table 2.

How would I do this? Can you provide syntax? I'm new.

Thanks.

View 2 Replies View Related

UPDATE Table A With Data From Table B

Aug 23, 2005

I'm doing a migration and need to clean up a table. I've done this in Oracle but can't get the syntax right for SQL.

Please help. Here is my feeble attempt:

UPDATE tableA
SET tableA.username = tableB.username
FROM tableA
JOIN tableB
ON tableA.email = tableB.email

View 2 Replies View Related

Update Table A From Table B's Data

Mar 11, 2008



helo, i'm the beginner in SQL Server...i have a problem to update table A...i have 2 tables
table A and table B
same field and same structure
i want to update data in table A,but the data i take from table B
table A : id,name,job,address
table B : id,name,job,address

how to insert data from table B to table A
and how to update data in table A?
thx.

View 5 Replies View Related

Update One Colum With Other Column Value In Same Table Using Update Table Statement

Jun 14, 2007

Hi,I have table with three columns as belowtable name:expNo(int) name(char) refno(int)I have data as belowNo name refno1 a2 b3 cI need to update the refno with no values I write a query as belowupdate exp set refno=(select no from exp)when i run the query i got error asSubquery returned more than 1 value. This is not permitted when thesubquery follows =, !=, <, <= , >, >= or when the subquery is used asan expression.I need to update one colum with other column value.What is the correct query for this ?Thanks,Mani

View 3 Replies View Related

Update Query Containg Static Data And Data From Another Table.

Sep 28, 2006

Hi,First post so apologies if this sounds a bit confusing!!I'm trying to run the following update. On a weekly basis i want toinsert all the active users ids from a users table into a timesheetstable along with the last day of the week and a submitted flag set to0. I plan then on creating a schduled job so the script runs weekly.The 3 queries i plan to use are below.Insert statement:INSERT INTO TBL_TIMESHEETS (TBL_TIMESHEETS.USER_ID,TBL_TIMESHEETS.WEEK_ENDING, TBL_TIMESHEETS.IS_SUBMITTED)VALUES ('user ids', 'week end date', '0')Get User Ids:SELECT TBL_USERS.USER_ID from TBL_USERS where TBL_USERS.IS_ACTIVE = '1'Get last date of the weekSELECT DATEADD(wk, DATEDIFF(wk,0,getdate()), 6)I'm having trouble combing them as i'm pretty new to this. Is the bestapproach to use a cursor?If you need anymore info let me know. Thanks in advance.

View 4 Replies View Related

Update With Data From Another Table

Dec 15, 2005

I'm trying to update a single record in a table using data from a single record in another table.  For the life of me I can't figure this out.  I'm trying to avoid having to write a bunch of +="  string stuff in C#.  Is there any way to do this with just SQL?Thanks in advance.

View 2 Replies View Related

Update One Table With Data From Another

Apr 11, 2008

I want to add to a column in one table the data in another. I have tried different update statements and none work. My update statement currently looks like this:

update t1
set t1.amtYTD = t1.amtYTD + t2.Total
from #ProgramData t1 join vw_MER_Reclass t2 on (t1.ProjId = t2.ProjId and t1.task = t2.task and t1.acct = t2.acct)

I need to take the amtYTD in table1, and add to it the value of Total in table 2.

Any help would be appreciated!

View 5 Replies View Related

Update Table With Excel Data

Jun 17, 2005

Can anyone tell me how to update a sql server table with the data from excel sheet? That would be very helpful.Thanks.

View 6 Replies View Related

How To Update Records With Data From Another Table

Sep 20, 2011

I want to update table2.message based on the criteria of table1.name. for example, all records named John will be updated with 'Msg1' in table 2.message. I am using MS SQL 2000 and below is the scenario.

table1 columns
ID
Name

table2 columns
ID
Message

Select a.Id, a.name, b.message
from table1 a, table2 b
where a.id =b.id

a.id a.name b.message
1 John Msg1
2 Steve Msg2
3 Scott Msg3
4 John NULL - update b.message to 'Msg1'
5 Steve NULL - update b.message to 'Msg2'
6 Scott NULL - update b.message to 'Msg3'
7 John NULL - update b.message to 'Msg1'
8 Steve NULL - update b.message to 'Msg2'

If i will update the record per name i am using the query below and i am pre-selecting all the existing names.

update table2 b
set b.message=(Select top 1 b.message
from table1 a, table2 b
where a.id =b.id

[Code] ...

How to update this in bulk without preselecting all the names?

View 7 Replies View Related

Table Update With Dynamic Data

Apr 23, 2008



OK, I'm trying to add some audit type information to a set of tables in my database. This involves adding 2 columns and sticking some data into those two columns. The columns themselves are added successfully, but I'm having troubles sticking any data into them - I'm getting a lot of errors. What I want to do is put a single character code in one column, and a datetime in the second. Here's the SQL I'm trying...




Code Snippet
SELECT @SQL = N'UPDATE ' + QUOTENAME(@TableName) + ' ' +
N' SET TRANSACTION_CODE = ''' + @TxCode +
N''', EFFECTIVE_DATE = ''' + @TxDateTime + ''';'
SELECT @Params = N'@TxCode varchar(1), @TxDateTime datetime'
EXEC sp_executesql @SQL, @Params, @TxCode, @TxDateTime





But this errors out with:

Msg 241, Level 16, State 1, Line 64

Conversion failed when converting datetime from character string.

I tried changing the datetime column to varchar, and CONVERT(varchar(30),@TxDateTime). That gets rid of the above error, but replaces it with the following (twice, I might add - one for each column?):

Msg 213, Level 16, State 1, Line 1

Insert Error: Column name or number of supplied values does not match table definition.

Any help is appreciated - let me know if you need more info.

View 14 Replies View Related

Reading And Writing To Same Table

Feb 16, 2008

I need to select all the records in a table, loop through them one by one, calculating some new field data, and then write the new data back to the same table. Here is the basic structure of what I've come up with:<CODE>SqlCmd = SqlConn.CreateCommandSqlStatement = "SELECT ProductID, Name FROM tblProducts"SqlCmd.CommandText = SqlStatementSqlRdr = SqlCmd.ExecuteReaderIf SqlRdr.HasRows Then  While SqlRdr.Read    If SqlRdr.FieldCount > 0 Then      ...      SqlWriteCmd = SqlConn.CreateCommand      SqlStatement = "UPDATE tblProducts SET Name = '" & NewName & "' WHERE ProductID = " & CStr(ProductID)      SqlWriteCmd.CommandText = SqlStatement      SqlWriteCmd.ExecuteNonQuery()      SqlWriteCmd = Nothing    End If  End WhileEnd IfSqlRdr.Close()SqlCmd = Nothing </CODE>I get an error that tells me to close out the Reader before trying to execute the write query. But I can't close it out for the loop to work properly. So I assume that there must be another way to do this simple task, but I'm so new to all of this that I need some help! Thanks! 

View 1 Replies View Related

Writing Txt File Into SQL Table

May 8, 2007

Hi,



My situation is:



For example i have txt file called serverlog.txt



txtfile contains:



serverid 3

Last log on 19/3/2007

Linkstatus OK



I have a table created with the following values



Table: serverlog

serverid(primarykey)

LastLogOn

LinkStatus



So my question is how do i get my txt file variables into the sql table.

Is there no import function in SQL?



Ive tried to do it with VB but thats doesnt work.



Greetings Sheila

View 23 Replies View Related

SQL Server 2008 :: Update One Row With Data From Different Row In Same Table

Sep 11, 2015

I need to update the Denominator column in one row with the value from the Numerator column in a different row. For example the last row in the table is

c010A92NULL

I need to update the Denominator, which is currently NULL, with the value from the Numerator where the MeasureID=c001 and GroupID=A.

This value is 668 so, the row should look like

c010A92668

create table dbo.TEST
(
MeasureID varchar(10),
GroupID char(1),
Numerator float,
Denominator float
)

[Code] .....

View 7 Replies View Related

Update/insert The Xml Data In Database Table

Oct 10, 2007

From: JAGADISH KUMAR GEDELA [jgedela@miraclesoft.com]
Sent: 10/10/2007 4:13:43 PM
To: jgedela@miraclesoft.com [jgedela@miraclesoft.com]
Subject: forum
Hi all,

I need to Insert the XML File data into SQL SERVER 2005 db(table).
For that I created the table with XML Native column (using typed xml)
*********************************create table command************
CREATE TABLE XmlCatalog (
ID INT PRIMARY KEY,
Document XML(CONTENT xyz))
***********************************
In order to Create the table with typed xml ,before that we have to create the xml schema which i
mentioned below
************************************create schema command********
CREATE XML SCHEMA COLLECTION xyz AS
'Place xml schema file ’
************************************
I created the xml schema file by using the xmlspy software.

--------------------------Insert command---------
INSERT into XmlCatalog VALUES
(1,'copy xml file ‘)
-------------------------------
I need to retrieve the xml data from the table
------------select query----------
SELECT Document.query (‘data (/X12//UserId)') AS USERID,
Document.query (‘data (/X12/X12_Q1/header/ISA//ISA_Authorization_Information_Qualifier)')
AS
ISA_Authorization_Information from XmlCatalog.
-----------------


I Need to update/insert/delete the xml data in the table

Can you please suggest the procedure to implement the above requirement(insert/update/delete)

View 5 Replies View Related

Writing Query Results To New Table

Dec 4, 2000

I have written several scripts to pull in nested info to the analyzer window. How do I get this data to write to the new table I have created in the database? here is the current script:

select Hierarchy_List.Hierarchy_Label as Hierarchy_Name,
Hierarchy_List.hierarchy_ID as Hierarchy_ID,
Hierarchy_List.Parent_ID as Parent_ID,
frequency_item.manufacturer as Motor_Make,
frequency_item.model as Frame
from hierarchy_list full outer join Frequency_item
ON HIERARCHY_LIST.HIERARCHY_ID = frequency_item.HIERARCHY_ID
where parent_id in (select hierarchy_id from hierarchy_list where parent_id in
(select hierarchy_id from hierarchy_list where parent_id in
(select hierarchy_id from hierarchy_list where parent_id in
(select hierarchy_id from hierarchy_list where parent_id=0)
and parent_id<>0) and parent_id<>0) and parent_id<>0)
and parent_id<>0 and frequency_item.description = 'motor'

I need to move this data to the VAER.Al_Machines and the column names are the same. I can move data via DTS, but it won't work on this because the nested info. Is there a script addendum I can add to this to execute both the search and the transfer in one job so I can automate it? Thanks for any help.

Mick Flanigan

View 2 Replies View Related

Writing Characters Into Table Problem

May 26, 2007

i have declared an attribute with datatype char(20) in sql server 7. and i tried to write words into the table. when i read them for comparison, if the word is less than 20 characters, i have include whitespaces to make it exactly 20 characters to match. why is this? and how can i solve this problem?

View 1 Replies View Related

OLE DB Command And Destination Writing To The Same Table

Sep 21, 2006

Hi,

I have a data flow task that performs an "upsert" by directing successful rows from a Lookup to an OLE DB Command that updates rows and unsuccessful rows (Lookup error output) to an OLE DB Destination for insertion.

The problem is that execution hangs when both tasks update/insert into the same table (execution is still hung after 20 minutes). Modifying the OLE DB Destination to insert into a different table succeeds (execution completese within 2 minutes). Replacing the OLE DB Destination with a Row Count transformation also works.

Could this be due to a table-locking issue? Any suggestions?

Thanks
ray

View 6 Replies View Related

Writing RowCount Variable To Table

Dec 5, 2006

I have a series of tasks in a Sequence Container. One of them is a Data Flow task, and inside that task is a Row Count transformation that counts the number of rows I add to a table. The Row Count transformation was added to record the number of rows written to a table in a log table.

When I try to retrieve the resulting variable (RowCount) in the Data Flow task, I get the default value (0). When I try to retrieve it in a subsequent task, I get the value 1. When I try to consume it in the OnPostExecute Event Handler of the original Data Flow task, I get a value of NULL.

1) When is the appropriate time to call the variable assigned to a Row Count transformation so it can be written to a log table?

2) Is there a way during debugging to see the set value of the RowCount variable?

I am using Microsoft SQL Server Integration Services Designer Version 9.00.2047.00 in Visual Studio 2005 Version 8.0.50727.42 (RTM.050727-4200)

Thank you in advance for your posts.

View 5 Replies View Related

Difficulty In Writing A DateTime To A Table

Jul 7, 2006

I'm developing an application in VB 2005 Express using SQL 2005 Express. I need to put a timestamp into my table each time I create a row...

The following is a snippet...

Dim DDate As [SqlDateTime] = Now()

Dim TheQuery As String = "INSERT INTO Groups (PC_Name_Stamp, OperatorNo, Group_Type, Date_Time) VALUES ('Development', '2', 'Test',' " & DDate & " ')"

Which won't work as I am attempting to concatinate a SqlDateTime into a string.

My best guess is that I need to somehow to use a DEFAULT value in the table that persists so each time a row is created the datetime it was created is saved with the row, rather than being re-calculated each time the table is opened. There are probably several other ways of doing it and this may not be the easiest.



I'm not a programmer, just an Engineer, so I can only read Help for 5 minutes at a time.

View 6 Replies View Related

SQL 2012 :: Possible To Allow A User To Insert And Update Data In A Table

Aug 14, 2015

Is it possible to allow a user to insert and update data in a table but prevent them from performing deletes against that same table? For auditing purposes I need to prevent the end users from being able to delete data.

View 1 Replies View Related

Stored Procedure To Copy Table 1 To Table 2 Appending The Data To Table 2.

Jan 26, 2006

Just wondering if there is an easy transact statement to copy table 1 to table 2, appending the data in table 2.with SQL2000, thanks.

View 2 Replies View Related

Writing ETL Error Records To A Common Table

Jun 13, 2007

I am working on building a template/design pattern for a DTS to SSIS upgrade project.



During our ETL processing, if we encounter a record that cannot be inserted into a destination table, we'd like to be able to write the entire record out to a common error/reject table. The obvious problem is that every SSIS package that is using this template will of course be dealing with varying table schemas.



I was thinking that if there were a way that I could transform the error record/buffer row into XML, I could then achieve my goal of having a common table to receive errors/rejects.



Has anyone done something like this, or have suggestions on how we might accomplish?



View 7 Replies View Related

Update Server Table Based On Flat File Data

Feb 13, 2014

I have a table dbo.Sales that contains all sales records. There is a column in that table called ItemNumber that I'd like to match with ItemNumber in a flat file and update the ItemCost based on the ItemCost column in the flat file.

So while there will be many sales records for each ItemNumber, I need to loop through and update the ItemCost in that sales record based on the corresponding ItemCost in the flat file. Does this make sense? I really need this for court and I can't figure out how to do it. I took a SQL course about 7 years ago but have forgotten everything.

Database Name: BTData
Database Table: dbo.Sales
Database Columns: ItemNumber (match on this), ItemCost (update this)

FlatFile Name: InventoryCosts.txt
FlatFile Columns: ItemNumber, ItemCost

There will be many sales records for each ItemNumber in the database table. I need to update each one with correct cost based on the item number and cost mapping from flat file.

View 1 Replies View Related







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