OUTPUT INSERTED INTO Can't Get Column Value When That Column Is Not Inserted

Aug 22, 2013

I'm doing a data migration job from our old to our new database. The idea is that we don't want to clutter our new tables with the id's of the old tables, so we are not going to add a column "old_system_id" in each and every table that needs to be migrated.

I have created a number of tables in a separate schema "dm" (for Data Migration) that will store the link between the old database table and the new database table. Suppose that the id of a migrated record in the old database is 'XRP002-89' and during the insert into the new table the IDENTITY column id gets the value 1, the link table will hold : old_d = 'XRP002-89', new_id = 1, and so on.

I knew I can get the value of IDENTITY columns with the OUTPUT INTO clause, although I have never actually used it. And now I can't get it to do what I need.

Below is some code to set up three tables: the old table, the new one, and the table that will hold the link between the id's of records in the old database table and the new database table.

Code:
CREATE TABLE DaOldTable(
pkCHAR(10)NOT NULL,
a_columnCHAR(10)
)
CREATE TABLE DaNewTable(
idINTNOT NULL IDENTITY,

[Code] ....

Below I tried to use the OUTPUT INSERTED INTO clause. Beside getting the generated IDENTITY value, I also need to capture the value of the old id that will not be migrated to the new table. When I use "OUTPUT DaOldTable.pk" the system gives me the error: "The multi-part identifier "DaOldTable.pk" could not be bound." Using INSERTED .id gives no problem.

Code:
INSERT INTO DaNewTable(a_column)
--OUTPUT DaOldTable.pk, INSERTED.id link_old2new_DaTable--(DaOld_id, DaNew_id)
SELECT a_column
FROM DaOldTable

[Code] ...

--but getting "The multi-part identifier "DaOldTable.pk" could not be bound."

DROP TABLE DaOldTable
DROP TABLE DaNewTable
DROP TABLE link_old2new_DaTable

How can I populate a table that must hold the link between the id's of records in the old database table and the new database table? The records are migrated with set-based inserts.

View 3 Replies


ADVERTISEMENT

Iterating A Column When A New Row Is Inserted

Oct 2, 2007

Hello everyone, I have a table in which I need to iterate field, possibly several rows, when I enter a new record with the same item ID number. An example will make this much clearer.

ItemID CurrentLocation Iter
A01 Inventory 1
A01 Cutting 0
A01 WIP 2
B01 WIP 0
B02 WIP 1
B02 Inventory 0


I dont want to delete any old rows so that I can keep a history of where each item has been. The iterative column is in reverse order so that 0 is the newest value (location) and higher numbers are older locations. An item could go through a CurrentLocation several times.

Now, if I insert a row with ItemID = A01 and Current Location = Polishing, I want the Iter field of all previous rows to iterate by +1 and this new row to have Iter = 0.

What would be the easiest, best way to do this? Use a stored procedure or do it in my code or what? I'm pretty new at SQL server so if i'm missing a better way to accomplish the same thing, then please point me in that direction. Thanks for your help and/or time.

Scott

View 3 Replies View Related

How To Display Column From Inserted Table

Jul 31, 2007

Hi all,

I have created a trigger in SQLExpress which looking for any insertion to a specific table in a database:

Create Trigger Tg_Insert on [tablename]
FOR Insert
AS
Select * FROM Inserted
---------------------------------------------------------
Assume there is nothing wrong with this trigger as I have already checked the output with Query tool.
My question is how can I display the newly inserted data to the client? In my case, Console application.
I want to do something like Console.WriteLine("data from inserted table here");
How can I achieve this? FYI, I'm using VS2005 with sqlexpress 2005.
Thanks in advance.

Regards,
SHAH

View 11 Replies View Related

Trigger On XML Column - Generate Mail If Particular Value Get Inserted In A Tag

Feb 26, 2014

We are having xml data in a column. Is it possible to write a trigger to generate a mail if particular value get inserted in a tag.

For ex:

<File AF="910" PTO="ATN_P76035_PSQO" NNO="54545465" KTNNN="AX2" KL="" AD="99" PrqnT="AX2" Stab="21545" KE="45454" TE="65465" Rsaa="BBBB" AK="54544.AX2.POEAX2.546546546.NONTP.NONTP" AK2="">

In the above xml data if we have the value 21545 in Stab the trigger needs to be executed and mail needs to be sent to a distribution list.

The Trigger should not be initiated if value other than 21545 is updated...

View 4 Replies View Related

Transact SQL :: Get Only Newly Inserted Rows By Datetime Column?

Aug 17, 2015

I have a TableA where data get inserted from Excel(IMPORT/EXPORT wizard)

TableA;
ID(identity)   Date (NOT NULL Defaulyt Getdate() )                          
 Name            Phone
1                   2014-06-17 17:28:21.190          
Nick              12345678910
2                  2014-05-17 17:28:21.190        
 Stan              00045678910
3                  2015-08-17 17:28:21.190        
 Kim                 11111678910
4                  2015-08-17 17:28:21.190          
Tom                NUll 

 3,4 are the rows i have inserted now , you can see by date, likewise i have 100,000 rows(old and new combination) and now the data from excel to TableA can be imported/exported daily , hourly, weekly basis.

Now i want to find out only the rows which are imported to tableA today, or hours back, or yesterday .....

 the reason is , 

Step1:get data from excel and import to tableA( this is a manual Step) and i know when the data is inserted  with exact date and time.

Step2: get newly inserted rows from TableA and pass them as Parameters in Stored Procedure.( i may run step 2 after 1 hour, or after  1 day or after 1 week ,but i want only rows that are inserted ) 

I tried with using where Datecreated, but did work.

View 4 Replies View Related

How To Solve Tables Or Functions 'inserted' And 'inserted' Have The Same Exposed Names.

Jul 23, 2005

Hi all!In a insert-trigger I have two joins on the table named inserted.Obviously this construction gives a name collition beetween the twojoins (since both joins starts from the same table)Ofcourse I thougt the usingbla JOIN bla ON bla bla bla AS a_different_name would work, but itdoes not. Is there a nice solution to this problem?Any help appriciated

View 1 Replies View Related

Getting Identity Of Inserted Record Using Inserted Event????

Jun 5, 2006

is there any way of getting the identity without using the "@@idemtity" in sql??? I'm trying to use the inserted event of ObjectDataSource, with Outputparameters, can anybody help me???

View 1 Replies View Related

Getting The Value That Was Just Inserted Passed Back Output Parameter

Mar 1, 2007

I have a SP that inserts data into a table with an identity column I want to get that id and use it in my response.redirect however I keep getting 0 back instead of  the identity. Relevent Sql 2005 Declare @NEWEMPID int --after an insert happens in sqlSet @NEWEMPID= SCOPE_IDENTITY()--last thing in my sqlReturn @NEWEMPID Or I tried NEWEMPID as an output parameter VB.Net  Dim retValParam As New SqlParameter("@NEWEMPID", SqlDbType.Int) retValParam.Direction = ParameterDirection.ReturnValue'execute the sqldatasource insert command
sqlEmpNewEmp.Insert()
Dim EmpIDVar As Integer = Convert.ToInt32(retValParam.Value) Response.Redirect("http://www.mysite.com?EMPID=" + Server.HtmlEncode(EmpIDVar)) sqlEmpNewEmp.InsertParameters.Clear() 

View 8 Replies View Related

How To Access Output (Inserted.ColName) From Client Application ?

Nov 6, 2006

I am using SQL Express 2005 and VB .net Express.

Question 1:

How can I get the result stored in Inserted.ColName (by Output clause of insert command). In the documentation (BOL) for SQL 2005, there is written "returned to the processing application for use" in Output clause (first paragraph).

Question 2:

How to store Inserted.ColName into local variable when insert command is running in stored procedure.:

View 8 Replies View Related

Inserted The Image In A Column----how Can I View The Image

Mar 7, 2006

hi,i have inserted the image present in mydocuments using alter commandcreate table aa(a int, d image)insert into aa values (1,'F:prudhviaba 002.jpg')when i doselect * from aai am getting the result in the column d as0x463A5C707275646876695C70727564687669203030322E6A 7067how i can i view the image?pls clarify my doubtsatish

View 2 Replies View Related

Using Output From A Stored Procedure As An Output Column In The OLE DB Command Transformation

Dec 8, 2006

I am working on an OLAP modeled database.

I have a Lookup Transformation that matches the natural key of a dimension member and returns the dimension key for that member (surrogate key pipeline stuff).

I am using an OLE DB Command as the Error flow of the Lookup Transformation to insert an "Inferred Member" (new row) into a dimension table if the Lookup fails.

The OLE DB Command calls a stored procedure (dbo.InsertNewDimensionMember) that inserts the new member and returns the key of the new member (using scope_identity) as an output.

What is the syntax in the SQL Command line of the OLE DB Command Transformation to set the output of the stored procedure as an Output Column?

I know that I can 1) add a second Lookup with "Enable memory restriction" on (no caching) in the Success data flow after the OLE DB Command, 2) find the newly inserted member, and 3) Union both Lookup results together, but this is a large dimension table (several million rows) and searching for the newly inserted dimension member seems excessive, especially since I have the ID I want returned as output from the stored procedure that inserted it.

Thanks in advance for any assistance you can provide.

View 9 Replies View Related

Nothing Is Being Inserted

May 13, 2007

I will paste my code below. Â I inserted a breakpoint but nothing is being sent to the database and nothing came up when I ran it with the breakpoint. Â Can anyone tell me how to fix this?Protected Sub btn_addfriend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_addfriend.Click Dim add_friend_source As New SqlDataSource add_friend_source.InsertCommand = "INSERT INTO [Friends] ([UserName], [UserID], [IP], [AddedOn], [FriendName]) VALUES (@UserName, @UserID, @IP, @AddedOn, @FriendName)" detailsview_addfriend.DataSource = add_friend_source add_friend_source.DataBind() add_friend_complete.Text = "Success!" End SubThe "Success!" text is the only thing that seems to work properly...

View 7 Replies View Related

Get Last Row That Was Inserted

Jan 1, 2008

Hello, I am stumped on how to get the last id that was inserted. I have searched all over the internet to find the answer but all of them turned up to be classic asp.

View 4 Replies View Related

Orw Is Not Inserted

Mar 18, 2008

while executing this command locally, ita working fine 
Insert into tblorderDetails
(OrderID,ProductID,SofaPackageID,Quantity,UnitPrice,TotalOrd,ItemStatus )
values(1, 3915, 0, 1, 2049.00, 2049.00, 'PO')
 but when executing online, giving me following msg:
(1 row(s) affected)
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Location16FreeStock'.
and also data is not inserted in table.
 

View 3 Replies View Related

Why Are &#34;&&#34; Inserted As &#34;_&#34;

Nov 4, 1998

I have a program to insert rows into a SQL Server table from an ASCII file. There appears to be some data mapping going on. For example:

"J & J Smith" is imported as "J _J Smith".

This doesn't happen on all servers. I can run it against my database and get the desired results.

I looked into the Server Configuation. Under the Security tab there are Mapping options. It appears that you can map _ to something else, but I don't see where you can map & to anything.

View 2 Replies View Related

Getting Last Inserted Value

Mar 3, 2007

hi,

this is my spc:
select top 1 u.userid,
u.user_name,
u.password,
c.code_description as role_code,
u.expiry_date,
u.created_date,
u.active,
convert(varchar,v. user_date, 103) + ' ' + right('0' + stuff(right(convert(varchar,v.user_date, 109), 14), 8, 4, ''), 10) as user_date,
v.operation,h.user_name as updatedby
from [usermaster] u inner join [codeMaster] c
on 'sp'=c.code inner join [HRUser_developerlog] v on u.userid=v.inserted_id and v.operation='update' inner join [usermaster] h on v.userid=h.userid
where u.userid = '3' order by v. user_date

if i use it gives the v.user_date as fist modified date it is not giving last modified date.

select * from HRUser_developerlog

user_date operat userid
ion
2007-01-25 14:28:17.000insert1
2007-01-24 13:02:18.093insert4
2007-03-03 11:30:29.310update2
2007-03-03 11:30:55.373insert3
2007-03-03 11:31:31.717insert26
2007-01-25 14:28:17.000insert3
2007-03-03 11:43:39.733update26
2007-03-03 11:48:04.543delete3
2007-03-03 14:26:22.420update3
2007-03-03 14:27:00.280update3
2007-03-03 14:27:12.013update2
2007-03-03 14:27:35.763update1
2007-02-08 14:28:17.030update2
2007-03-03 14:27:55.967update3
2007-03-03 14:29:18.827update3
2007-03-03 14:30:52.983update3


so it has to show
2007-03-03 14:30:52.983
but it shows the first updated id only
2007-03-03 14:26:22.420

please help me to get my need

View 6 Replies View Related

DataSet - Inserted Row ID

Jan 24, 2007

I have a dataset that uses generated stored procedures to do its select, insert, update, delete.  I am inserting a row to that dataset, and after the update, using the ID of newly created row.  This worked just fine until I added triggers to some of the tables on my DB, and now, when I insert a row, the row's ID is not available after the update (it's 0) Any idea what happened / what I have to do to fix this? Thnx! 

View 1 Replies View Related

Return Inserted Row

Jul 23, 2007

how do i insert a record, then return the inserted record back to VS (ASP + VB) to display? maybe just the ID will be enough. then i will do a select 

View 6 Replies View Related

Getting The Id Of The Row That I Inserted With SQL 2005

Aug 9, 2007

Hi,I use a Stored Procedure who works very well....INSERT INTO Computers (CategoryID, SubCategoryID, ......VALUES (@CategoryID, @SubCategoryID, .........But as soon as it creates the new row, i want to be able to get the Id (ComputerId) of this row. I use ComputerId as the primary key.How can i do that? I code in VB.Thanks

View 2 Replies View Related

How Do I Retreive Id Of Just Inserted Row?

Nov 3, 2007

I'm creating a web application that has user input on 3 seperate pages. Each page prompts the user for specific information and at the bottom of the page the user will click on the "Submit" button to post the info from the form to the database table.
Once the user has submitted the first page of information how do I retrieve the ID from the CustID column of that row so I can use the Update function to add additional info to that row when the user clicks on the submit button on page 2 & 3. I don't want to hold all the information in variables until the end in case they bail out of the form.
TIA
Steve

View 7 Replies View Related

Need To Get The ID Of The Last Record That Was Inserted

Dec 22, 2007

I've seen a lot of info on how to do this with @@IDENTITY and SCOPE_IDENTITY(), but can't  get this to work in my situation.
I am inserting a record into a table.  The first field is a GUID (UNIQUEIDENTIFIER) that uses newid() to generate a unique GUID.  Since I am not using an int, I can't set the IsIdentity property of the field.  Without IsIdentity set, @@IDENTITY and SCOPE_IDENTITY() do not work.
How can I get the ID (or whole record) of the last record that I inserted into a SQL database?  Note that I am doing this in C#.
As a last resort, I could generatate the GUID myself before the insert, but I can't find C# code on how to to this.

View 10 Replies View Related

How Return Inserted ID

Mar 10, 2008

 Hi!
I would like to get the last inserted ID in a sql 2005 table  to a variable.My code is:
SqlDataSource ds = new SqlDataSource();ds.ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ToString();ds.InsertCommandType = SqlDataSourceCommandType.Text;ds.InsertCommand = "INSERT INTO Products(SellerID, Price) OUTPUT INSERTED.ProductID VALUES(@SellerID,@Price)"; ds.InsertParameters.Add("SellerID", "Sony"); ds.InsertParameters.Add("Price", "123");string output = ds.Insert().ToString();  // it's return rowsAffected but I need  productID (SCOPE_IDENTITY or @@IDENTITY )Thank you for your time and help :)
            

View 4 Replies View Related

Get Value Of Rowguidcol From Last Inserted Row

Feb 3, 2004

How would I get the value of a ROWGUID column of the row I just inserted? (like using @@identity for an identity column.)

Thanks!

View 6 Replies View Related

How Do I Get The Uniqueidentifier Of Just Inserted Row?

Apr 18, 2004

Hello there!

it was a while since i studied SQL and that brings us to my problem...

I'm creating a Stored Procedure wich first insert information in a table. That table has a uniqueidentifier fild that is default-set to newid().

later in the SP i need that uniqueidentifier value? how do I get it?

I tried this:

CREATE PROCEDURE spInsertNews
@uidArticleId uniqueidentifier = newid,
@strHeader nvarchar(300),
@strAbstract nvarchar(600),
@strText nvarchar(4000),
@dtDate datetime,
@dtDateStart datetime,
@dtDateStop datetime,
@strAuthor nvarchar(200),
@strAuthorEmail nvarchar(200),
@strKeywords nvarchar(400),
@strCategoryName nvarchar(200) = 'nyhet'
AS
INSERT INTO tblArticles
VALUES( @uidArticleId,@strHeader,@strAbstract,@strText,@dt
Date,@dtDateStart,@dtDateStop,@strAuthor,@strAutho
rEmail,@strKeywords)

declare @uidCategoryId uniqueidentifier
EXEC spGetCategoryId @strCategoryName, @uidCategoryId OUTPUT

INSERT INTO tblArticleCategory(uidArticleId, uidCategoryId)
VALUES(@uidArticleId, @uidCategoryId)


But i get an error when I EXEC the SP like this:

EXEC spInsertNews
@strHeader = 'Detta är den andra nyheten',
@strAbstract = 'dn första insatt med sp:n',
@strText = 'här kommer hela nyhetstexten att stå. Här får det plats 2000 tecken, dvs fler än vad jag orkar skriva nu...',
@dtDate = '2003-01-01',
@dtDateStart = '2003-01-01',
@dtDateStop = '2004-01-01',
@strAuthor = 'David N',
@strAuthorEmail = 'david@davi.com',
@strKeywords = 'nyhet, blajblaj, blaj'


the errormessage is: Syntax error converting from a character string to uniqueidentifier.


does anyone have a sulution to this problem?
Can I use something similar to the @@IDENTITY?
I will be greatful for any ideas...

thanks
/David, Sweden

View 8 Replies View Related

Return ID Of The Last Inserted Row

Apr 6, 2006

Hello,
I want to return the ID of the last inserted row. I am using an ObjectDataSource and a FormView to perform the insert operation. Here is my presentation code:
<asp:ObjectDataSource ID="odsOrders" runat="server" DataObjectTypeName="Auction.Info"InsertMethod="InsertOrder" SelectMethod="GetOrders" OnInserted="ReturnNewOrderID" OldValuesParameterFormatString="original_{0}" TypeName="Auction.Controller">    <SelectParameters>        <asp:Parameter DefaultValue="00" Name="ModuleId" Type="Int32" />    </SelectParameters></asp:ObjectDataSource>
        <asp:FormView ID="fvAddOrder" runat="server" DataSourceID="odsOrders" DefaultMode="Insert" HorizontalAlign="Center" Width="100%">            <InsertItemTemplate>....
and my VB code:
        Protected Sub ReturnNewOrderId(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)            Response.Write(e.ReturnValue)            Response.Write("Test")        End Sub
and my Stored Procedure:
ALTER PROCEDURE [dbo].[Auction_InsertOrder] (@ModuleID int,@FirstName nvarchar(50),@LastName nvarchar(50),@Email nvarchar(250),@Phone nvarchar(20),@Fax nvarchar(20),@DelAddress1 nvarchar(250),@DelAddress2 nvarchar(250),@DelTown nvarchar(50),@DelPostCode nvarchar(20),@DelCountry nvarchar(50),@InvAddress1 nvarchar(250),@InvAddress2 nvarchar(250),@InvTown nvarchar(50),@InvPostCode nvarchar(20),@InvCountry nvarchar(50),@AuctionName nvarchar(50),@Quantity int,@Price decimal(18,2),@PostCosts decimal(18,2))ASINSERT INTO Auction_Orders(ModuleID, FirstName, LastName, Email, Phone, Fax, DelAddress1, DelAddress2, DelTown, DelPostCode, DelCountry, InvAddress1, InvAddress2, InvTown, InvPostCode, InvCountry, AuctionName, Quantity, Price, PostCosts, DateEntered)VALUES (@ModuleID, @FirstName, @LastName, @Email, @Phone, @Fax, @DelAddress1, @DelAddress2, @DelTown, @DelPostCode, @DelCountry, @InvAddress1, @InvAddress2, @InvTown, @InvPostCode, @InvCountry, @AuctionName, @Quantity, @Price, @PostCosts, getdate())RETURN SELECT @@IDENTITY As NewOrderID
I can insert the record into the database but the e.ReturnValue does not return anything.
Thank you for your help/
Many thanks,
Vincent
 

View 2 Replies View Related

Find What I Just Inserted

Jun 23, 2004

Hey!

I need to find the record_id of the record I just inserted so that I can display the newly created record id.

Right now it looks like this: (I'm using Cold Fusion to insert and retrieve records, but I think this is an SQL question)

INSERT INTO table (value1, value2, value3) values (value1, value, value3)

Select record_id
FROM table
WHERE value1 = value1 AND value2 = value2 AND value3 = value3


The problem is when someone puts in the exact same data for values 1 through 3 I get back only the first record_id, not the last one. Maybe that's the trick right there, add an ORDER BY field_id DESC??

I thought MySQL had a way to grab the last inserted record, or return the record_id while I'm still in the insert statement, that would be preferable.

-Matt

View 5 Replies View Related

Is There A Way To Return The PK ID Of The Row Inserted?

Jan 6, 2007

When I insert a row I need the PK assigned to that row. Is there a way to do this.

View 4 Replies View Related

How Do I Get The Uniqueidentifier Of Just Inserted Row?

Apr 18, 2004

Hello there!

it was a while since i studied SQL and that brings us to my problem...

I'm creating a Stored Procedure wich first insert information in a table. That table has a uniqueidentifier fild that is default-set to newid().

later in the SP i need that uniqueidentifier value? how do I get it?

I tried this:

CREATE PROCEDURE spInsertNews
@uidArticleId uniqueidentifier = newid,
@strHeader nvarchar(300),
@strAbstract nvarchar(600),
@strText nvarchar(4000),
@dtDate datetime,
@dtDateStart datetime,
@dtDateStop datetime,
@strAuthor nvarchar(200),
@strAuthorEmail nvarchar(200),
@strKeywords nvarchar(400),
@strCategoryName nvarchar(200) = 'nyhet'
AS
INSERT INTO tblArticles
VALUES( @uidArticleId,@strHeader,@strAbstract,@strText,@dt Date,@dtDateStart,@dtDateStop,@strAuthor,@strAutho rEmail,@strKeywords)

declare @uidCategoryId uniqueidentifier
EXEC spGetCategoryId @strCategoryName, @uidCategoryId OUTPUT

INSERT INTO tblArticleCategory(uidArticleId, uidCategoryId)
VALUES(@uidArticleId, @uidCategoryId)


But i get an error when I EXEC the SP like this:

EXEC spInsertNews
@strHeader = 'Detta är den andra nyheten',
@strAbstract = 'dn första insatt med sp:n',
@strText = 'här kommer hela nyhetstexten att stå. Här får det plats 2000 tecken, dvs fler än vad jag orkar skriva nu...',
@dtDate = '2003-01-01',
@dtDateStart = '2003-01-01',
@dtDateStop = '2004-01-01',
@strAuthor = 'David N',
@strAuthorEmail = 'david@davi.com',
@strKeywords = 'nyhet, blajblaj, blaj'


the errormessage is: Syntax error converting from a character string to uniqueidentifier.


does anyone have a sulution to this problem?
Can I use something similar to the @@IDENTITY?
I will be greatful for any ideas...

thanks
/David, Sweden

View 1 Replies View Related

Inserted Table ?

Nov 3, 2005

Trying to get my head around this table:

I thought it contained all data used in an insert; meaning if i enter a row in a table the inserted table should then contain all data entered?

Ive created multiple tables linked via primary key Learner_ID this key is unique to any/all students and can never be duplicated hence i thought i would use it to link the tables.

I have tables Fab / Main / Elec / Learner_info / WS_WR.

For Fab / Main / Elec the only data i need form Learner_info is the Learner_ID field, i simply used:

INSERT INTO FAB(Leaner_ID)
SELECT Learner_ID
FROM Inserted

as a trigger to insert the ID into these tables. Everything works perfectly fine. So i assumed that i would be able to use something very similar to insert say:

Learner_ID, FNAME, LNAME, ONAME and C_NUM from the learner_info table into the WR_WS table. Apparently i was wrong I can insert the learner_ID perfectly but if i then try to add another insert trigger eg: insert fname i get an sql error:

Cannot insert the value NULL into the column 'LEARNER_ID', table 'swdt_im.WS_WR'; column does not allow nulls. INSERT fails.

Now from reading the error it suggests to me that because the second trigger is running my learner_id value has become a NULL. Obviously a primary key wont accept this value so the statement fails.

What im struggling to understand, im sure i will solve the problem eventually but i would apreciate help, and this is most important to me rather than a solution is this:

If i enter data into a row on a table does that data go into the inserted table in the same row? or does the data go into inserted as a single entry row, meaning when i tab along from learner_ID into FNAME does Learner_ID become row 1 (in inserted) and FNAME the current row? or do they go into the appropriate columns?

I was under the assumption that i could enter:

LEARNER_ID / FNAME / LNAME / ONAME / C_NUM

into one table and have a trigger insert those values into multiple other tables. Dont suppose someone can help me out im alright querying a SQL db but ive never had to develop anything other than a single table one myself before

Thanks in advance

View 1 Replies View Related

From Inserted Question

Mar 20, 2008

I have created an updatabable view.

It uses the INSTEAD OF INSERT clause to fire because there are multiple base tables.


lets say the view has 6 fields
field1,field2, field3, field4, field5, field6

to get the values from the inserted record I have to declare the variables first

declare field1 varchar(50),field2 varchar(50), field3 varchar(50), field4 varchar(50), field5 varchar(50), field6 varchar(50)


I then have to assign the information to these variables

select @field1 = field1,@field2 = field2,@field3 = field3, @field4 = field4,@field5 = field5,@field6 = field6 from inserted

I can then use these values to execute store procedures

exec sp1 @field1, @field2, @field3
exec sp2 @field4, @field5, @field6


is there anyway to just do this

exec sp1 inserted.field1, inserted.field2, inserted.field3
exec sp2 inserted.field4, inserted.field5, inserted.field6


I tried
exec spec select field1, field2, field3 from inserted and it did not give me an error message BUT it did not work

I would like to use my stored procedures for data insertion

I appreciate your help

View 2 Replies View Related

Getting An Int Id From An Inserted Record

Jul 20, 2005

Hello,I would like do an insert into a table. The table has an autoincrimenting unique int id. After I do the insert how do i get theunique int id of the record that I just inserted? Is there a straightforward way of accomplishing this?Thanks,Billy

View 6 Replies View Related

How WCF Can Get New Inserted SQL Data ?

Oct 25, 2007

dear all,

I have a WCF service which is host in a console application for the time beeing.
This service provide methods for retriving history data when request.
So far so good.

My WCF service need also to know when a particular table (ALARMS tabel ) gets updated with DELETE, INSERT, OR UPDATE. This because my client application (WinForm) need to refresh a datagrid binding to that ALARMS table.

In other words my WCF servcie would send a callback event to my client when it as been notice for a change..

But my problem is how my WCF service can be notify from an update in my SQL table ?
I have tried SQLDependency class, but I give up was not working properly...and hard to know the xact context you are runing on.
Was thinking also of having a timer whcih pool every 1s by calling my tabel store procedure and verifiy is somerow ha changed....

What to do, how to do, what is the best way and thred safe method

Thnaks for help and advise

regards
serge

View 8 Replies View Related

Getting Inserted Data In Trigger

Feb 22, 2007

I am using SQL Server 2000.I want to create an after insert trigger on one of my tables, but I have forgotten how I reference the inserted data to do some business logic on it. Can someone please help. Thanks Jag 

View 1 Replies View Related







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