Executing Store Procedre By Calling It From An Insert Trigger?

Feb 10, 2000

hi, I have a trigger on a table for insert, once there is new data into that table I want to run a nother store procedure by passing all input from inserted to the store procedure as input parameter. can I do that.

Thanks

Ali

View 4 Replies


ADVERTISEMENT

Instead Of Insert, Update Trigger Calling A Stored Procedure Question

Oct 26, 2006

I have to control my business rules in a Instead of Insert, Update Trigger.

Since the Control Flow is quite complicated I wanted to break it into stored procedures that get called from within the trigger.

I know that Insert Statements embedded in a Instead of Trigger do not execute the Insert of the trigger you are calling.



But... If I embed stored procedures that handle my inserts in the Instead of Insert trigger call the trigger and put in a endless loop or are the stored procedure inserts treated the same as trigger embedded inserts.

View 7 Replies View Related

Calling SQLCMD From Within An Executing Procedure

Apr 4, 2008

Is there a way to call SQLCMD from within an executing procedure?

View 3 Replies View Related

Executing SP Having A Dynamic Cursor Fails In Calling SP

Apr 21, 2008

Hi,
In a stored procedure (SP1) I call another stored procedure (SP2), passing along parameters. In SP2 I dynamically build cursor c1. I can execute SP2 without any problems but when I start SP1 I get the following message:

Msg 16916, Level 16, State 1, Procedure SP2, Line 114
A cursor with the name 'C1' does not exist.

Yes, the cursor is of type GLOBAL. I am sure I miss something here ...
Any help is highly appreciated !

Thanks: Peter

View 1 Replies View Related

Calling Store Procedure

Mar 10, 2008

I have created a database and stored procedure there.I want to execute that store procedure having dot net in my front end,i.e i want to execute store procedure from .net.How can I do that.Pls help me.

View 1 Replies View Related

Executing Store Procedure

Feb 13, 2008

 
I have the following code. User clicks on a button, then textbox with
calendar icon is displayed, calendar appears when icon is clicked, user
selects date, date is populated in the textbox field.  The value in the
textbox field is passed to a stored procedure.  How can I check if the
sp call was successful and what can I do to add a message to the user.
 Also, is the control flow appropriate or should I change it? Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click     TextBox1.Visible = True        ImageButton1.Visible = True         If Calendar1.Visible = True Then        ElseIf TextBox1.Text <> "" Then             ' Create connection            Dim conn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection(SQLSTRING.ConnectionString)            conn.Open()            ' Create command            Dim cmd As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand()            cmd.Connection = conn            cmd.CommandType = Data.CommandType.StoredProcedure            cmd.CommandText = "sp"            cmd.Parameters.Add("@date", Data.SqlDbType.DateTime)            cmd.Parameters("@date").Value = Convert.ToDateTime(TextBox1.Text)            cmd.ExecuteNonQuery()            conn.Close()        Else            Response.Write("You must select a date.")         End If 

View 6 Replies View Related

Executing A Store Procedure

Apr 29, 2004

Hi,

I Have the next problem:

I have a store procedure in my db which is called from an aplication (developed in Java). That sp contains a cursor which updates regs from a table. After calling from the java application I notice that some regs of the cursor have not entered in it, i mean if the sp executes 200 iterations in the cursor only 150 have worked. But all the iterations enter when i call the sp from the query analyzer!!! and it takes more time too.

Does anybody know something about it?????

View 1 Replies View Related

Calling Store Procedure From Aspx

Jun 7, 2004

hi , I would appreicate your help, I have created a store procedure in MS sql server 2000 to be called from aspx page.
The store procedure will have multiple functions:
checking if a file exist in c:data
if file exist, it will use zip file command line to unzip the file and then run DTS package to upload the database.

The issue I am having is when I run the store procedure from MS query analyzer,I get a confirmation that the whole procedure ran successfully, but when I call the same procedure from aspx, althought the store procedure ran successfully, but I did not get any confirmation to the user in the aspx page to notify the user that the process successed.... here is my code in where I think is not working,
CREATE PROCEDURE p_on_demand_dts_sales_option_price_report_3_ftest
@id int , @msg_output varchar(28) output
as
declare @varcmd varchar(255),@FileExist int
select @varcmd = null
select @varcmd ='dir :Data_on_demandsales_option_price_report.csv' -- check if file exist
EXEC @FileExist = master..xp_cmdshell @varcmd
set @msg_output = 'The file exists'
Return 44

+++ The above store procedure use command line to check if the csv file exist, its suppose will return a output parameter and a return # BUT it did not. To my surprise, when I modify the above store procedure like this, it work
-----
CREATE PROCEDURE p_on_demand_dts_sales_option_price_report_3_ftest
@id int , @msg_output varchar(28) output
as
set @msg_output = 'The file exists'
Return 44

The second procedure does not do anything, except take input parameter and return a message output and return, this work.

since the second procedure works, it means that the code in aspx is correct, but I have no clue why it does not return output parameter and return # in the first procedure.

I would really appreciate anyone who could help.
thanks

ehx5

View 4 Replies View Related

Executing A Package From Store Procedure

Jul 31, 2001

How can I execute a package from a store procedure. The package function will export a table to a text file in c:export.

I can run the package manually by clicking on it to execute it. I am looking for another way to run the package from a store procedure. any ideas
Thanks

Ali

View 1 Replies View Related

Calling DB2 Store Procedures From SQL Server 2000

Feb 5, 2004

I am trying to call DB2 stroe procedure from within SQL server 2000 using DTS. I have the IBM odbc driver installed on the server. I have created an ACtiveX script to run in DTS and it fails staing it could not findor load the DB2 store procedure.

Has anyone come across doing this and how they did it?

THanks for the help....

View 4 Replies View Related

EXECUTING STORE PROCEDURE IN SELECT STATMENT

Aug 27, 2001

hI
DOES ANY BODY KNOW HOW TO EXECUTE STORE PROCEDURE IN SELECT STATMENT

THANKS
jk

View 1 Replies View Related

Calling The Same Store Procedure Repeatly, But Only Work In The First Time

Apr 18, 2006

I had try calling a function, that call a store procedure, repeatly using a for loop, but I notice it will only get the expected part_id in the first time, and return an empty string sub-sequentially without throwing an exception. So I had try using a sql query instead, but the same thing happen. Below is my function, can you point out to me what's wrong?
My original version that calls a store procedure
Public Shared Function getPartId(ByVal part_supplierserialnumber As String) As String
Dim mySqlCommand As New SqlCommand
Dim mySqlConnection As SqlConnection = New SqlConnection(GetERATSConnectionString())
Dim myPart_id As String
mySqlCommand.CommandType = CommandType.StoredProcedure
mySqlCommand.CommandText = "getPartId"
mySqlCommand.Connection = mySqlConnection
mySqlCommand.Parameters.Add(New SqlParameter("@part_supplierserialnumber", part_supplierserialnumber))
Try
mySqlConnection.Open()
myPart_id = mySqlCommand.ExecuteScalar()
Catch ex As Exception
myPart_id = ""
Finally
mySqlConnection.Close()
mySqlConnection.Dispose()
End Try
Return myPart_id
End Function
My Store procedure
create procedure getPartId@part_supplierserialnumber as nvarchar(50)as
select top 1 part_id from tblPtSingapore where part_supplierserialnumber = @part_supplierserialnumber order by part_datecreated desc
 
GO
The new version I tried which happen the same thing
Public Shared Function getPartId(ByVal part_supplierserialnumber As String) As String
Dim myPart_id As String
Dim strSql As String = "select top 1 part_id from tblPtSingapore where part_supplierserialnumber = '" & part_supplierserialnumber & "' order by part_datecreated desc"
Dim mySqlConnection As SqlConnection = New SqlConnection(GetERATSConnectionString())
Dim mySqlCommand As New SqlCommand(strSql, mySqlConnection)
Try
mySqlConnection.Open()
myPart_id = mySqlCommand.ExecuteScalar()
Catch ex As Exception
myPart_id = ""
Finally
mySqlConnection.Close()
mySqlConnection.Dispose()
End Try
Return myPart_id
End Function

View 2 Replies View Related

T-SQL (SS2K8) :: Calling SSIS Package Through Store Procedure

Dec 4, 2014

I am calling Store Procedure from my C# Code and inside the SP, I am calling my SSIS Package.It is working fine. On my local because I have all rights to run xp_cmdshell COMMAND. Now I have to transfer this SP to QA and Prod and I don't have rights to run xp_cmdshell COMMAND.

Here is my SP.

declare @cmd varchar(1000)
SET @ssispath = 'SSIS Package Path where my .dtsx package'
set @ExcelF = 'Passing My source file name and full path'

select @cmd = 'C:"program files (x86)""Microsoft SQL Server"100DTSBinnDTEXEC.exe /F "' + @ssispath + '"'
select @cmd = @cmd + ' /X86 /SET Package.Variables[User::ExcelF].Properties[Value];"' + @ExcelF + '" /X86 '
exec master..xp_cmdshell @cmd

My question is, is there other way to run/execute above Store Procedure/SSIS without XP_CMDSHELL Command?

View 6 Replies View Related

Calling Eventcreate Command From Xp_cmdshell Store Procedure

Feb 15, 2008



Hi,

I want log event in event logger using xp_cmdshell store procedure.
I am calling eventcreate dos command.


xp_cmdshell 'C:> eventcreate /S \servername /L Application /T Success /SO Application Name /ID 1754 /D €śDescription of event€? '

I am getting error....


Incorrect syntax near 'eventcreate' /S \206.245.13.94' /L Application' /T Error' /SO WIPError'/ID 123'/D "Testing"'.


please help me.

thanks,

Chetan S. Raut.

View 5 Replies View Related

Executing DDL In A Trigger

Nov 15, 2000

Dear All,
I would like to execute a DDL statement(create table) in a trigger. The DDL statement is stored as a field in another table. I have read that sql statement into a variable of type varchar. How do I execute that sql statement.
Thanks in advance

View 3 Replies View Related

Executing Trigger

Nov 28, 2007



Hi Everybody,


I am new to ms sql server i had small proublem

i am created Trigger it will work so fine command successfully

how can i executed that Trigger plz help

Regards
subu

View 4 Replies View Related

Trigger Not Executing

Aug 13, 2006

I will try to keep this as simple as possible and make a long story short. The college I work for has bought a third party package to basically run the operations of the school. There is a component for registration, admissions, billing, etc. It also has a web component so students can access their school information from anywhere. The backend for all of this is SQL Server. To make things easy, the vendor has provided us with the steps to bulk load users, via DTS, into the system and create their accounts for the web portion. The way this works is as follows:

I create a CSV file which I then load via DTS into their "Bulk Load" table. This table has an "on insert" trigger that fires off when the load happens on the "Bulk Load" table. The trigger verifies that the user exists in the system, encrypts the password I provide in the file and inserts the record into an "Accounts" table. This "Accounts" table is where the system checks when a user logs in. Everything works fine on our test server, but in live, the trigger does not execute. The DTS package executes and the "Bulk Load" table gets updated, but the "Accounts" table does not. My file has 382 valid students and again, it worked fine on the test server.

Differences between the servers:

1. The DTS packages are the same, except for the server they connect to.

2. The test server is stand alone, while the production server is clustered.

What I tried:

1. A ran the alter statement to enable the trigger thinking it might be disabled.

2. Dropped the trigger on production and re-created it with the trigger from our test server.

3. Tried to run a trace (I had never done that before). Noticed some sp's running, but none of them were sp's found in the trigger.



Any thoughts or ideas as to what I can check? Do triggers have certain permissions and if so, where can I make sure I have the permissions. I should have full access under my account as should the account that SQL Server Agent is logged in as.

Thanks for any help.

Pete

View 17 Replies View Related

SQL Server 2008 :: Importing SSIS Package Into File Store And Calling It Within A Job

Oct 9, 2015

I've imported an SSIS package into Management Studio (2008 R2) and I've set up a SQL Server Agent job to call the package but it fails due to error code: 0xc00160aa.

As far as I can tell this is because it is unable to read the location of the package despite it being a file system location within Management studio. Also I can run the package manually within Management Studio, but when I try to call it via the job it fails.

View 0 Replies View Related

Calling Webservice From A Trigger

Jun 26, 2007

Is it possible to call/fire a method in a webservice (.asmx) from a trigger in MS SQL 2005? I would like to send out a notification to all the admins whenever a new row is inserted into a table in our db. If possible, can someone show me an example of how to?

View 1 Replies View Related

DB Engine :: Calling Exe From Trigger

May 12, 2015

I tried to call a exe from sql server through trigger with xp_cmdshell, But its not working as expected, shows preemptive_os_pipeops in process under the activity monitor and the process got hang.

View 18 Replies View Related

Calling VB.NET Function From SQL Trigger

Nov 27, 2007


I have VS 2003 & SQL Server 2005.I have created VB.NET console application which calls various function. Based on data insertion/ updatation in SQL 2005 I need to call function from my VB.NET application. That is from SQL insert/update trigger I need to call function from my console application which is continuouly running.


I need help on how can I capture insert trigger event VS 2003 console application?

View 2 Replies View Related

Sql Command Executing Trigger

Jan 5, 2004

hi.
I must get i trigger the sql command, which execute trigger.

View 5 Replies View Related

SQL 2012 :: Executing SP From Trigger?

Mar 21, 2014

Below is my requirement..

Create trigger on Table_XYZ ( After Insert,After Update)
select @var=Col_Last field is null from inserted
if @var is null
Execute sProc1
create proc sproc1
Business logic will create two csv files. Success and error files
success record will be deleted from Table_XYZ,
Error records updated with error_message.

Problem:- When i am updating Col_Last value to null or insert a record with NULL for Col_Last

Trigger is firing and executing SP.....But i was not able query the Table_XYZ and taking too much time...

sp_who2 shows blocked by...my SPID only

when i am executing SP alone ...every thing works fine....

when i am doing testing on trigger with Insert/Update... i am getting executinf query... no response...

If i comment below ones in Trigger...working fine...

--if @var is null
--Execute sProc1

View 1 Replies View Related

Executing A Views From A Trigger

Mar 1, 2006

Hi,I am new to using SQL. I want to be able to exucute a query that Iplace in a view. I want this views to be executed every time a valuechange in one of the table in a particular field. So my guess was touse a trigger that will call the views every time the data change inthe selected table. Is this the proper way of doing thing? Should Iuse other SQL tools to achive this. I search for exemple of triggerexecuting views but did not found anything as of yet. Let's use thisdummy name for the exemple:Database: DB1Table: Tbl1Special field in Tbl1: flagViews name: views_01Thank you.Philippe

View 7 Replies View Related

Trigger Calling Stored Procedure???

Mar 7, 2001

can a trigger firing cause a stored procedure to execute!! if this can be done then I will have more questions to follow! thanks, Scott

View 1 Replies View Related

Calling Stored Procedure In Trigger

Mar 17, 2004

Hi

I have a problem calling stored procedure in trigger..

When no exception occures stored procedure returns the value but if any exception occures executing that stored procedure then stored procedure will not return any value..

I have handled exception by returning values in case if any..

Here is the stored procedure

CREATE PROCEDURE BidAllDestinations
(
@ITSPID int,
@DestinationID int,
@BidAmount decimal (18,4),
@BidTime datetime,
@intErrorCode int out
)

AS
DECLARE @GatewayID int
DECLARE @GatewayExist int
SET @GatewayID = 0
SET @GatewayExist = 0
SET @intErrorCode = 0

UPDATE BID FOR CORRESPONDING GATEWAY
DECLARE GatewayList CURSOR FOR

SELECT Gateways.GatewayID
FROM Gateways INNER JOIN
GatewayDestinations ON Gateways.GatewayID = GatewayDestinations.GatewayID INNER JOIN
ITSPs ON Gateways.ITSPID = ITSPs.ITSPID
Where Gateways.ITSPID = @ITSPID AND DestinationID = @DestinationID

OPEN GatewayList

FETCH NEXT FROM GatewayList INTO @GatewayID

IF (@GatewayID = 0)

SET @intErrorCode = 1
ELSE
BEGIN
-- CHECK @@FETCH_STATUS TO SEE IF THERE ARE ANY MORE ROWS TO FETCH
WHILE @@FETCH_STATUS = 0

BEGIN


SELECT@GatewayExist = Gatewayid
FROMTerminationBids
WHEREGatewayid = @Gatewayid AND DestinationID = @DestinationID

IF @GatewayExist > 0

UPDATE TerminationBids
SET BidAmount = @BidAmount,
BidTime = getdate()

WHERE GatewayID = @Gatewayid AND DestinationID = @DestinationID

ELSE

INSERT INTO TerminationBids (GatewayID, DestinationID, BidAmount)
VALUES (@GatewayID,@DestinationID,@BidAmount)

IF @@ERROR <> 0
BEGIN
GOTO PROBLEM
CLOSE GatewayList
DEALLOCATE GatewayList
END

FETCH NEXT FROM GatewayList INTO @GatewayID

END
CLOSE GatewayList
DEALLOCATE GatewayList

END
PROBLEM:
BEGIN

SET @intErrorCode = 100


END
RETURN @intErrorCode
GO


TRIGGER CODE:::

CREATE TRIGGER TR_TerminationBid
ON dbo.TerminatorBidHistory FOR INSERT

AS

DECLARE @ITSPID int
DECLARE @DestinationID int
DECLARE @BidAmount decimal (18,4)
DECLARE @BidTime datetime
DECLARE @intErrorCode INT
DECLARE @DistinationList varchar (8000)
DECLARE @DestinationLevel varchar (100)
SET @intErrorCode = 0
SET @ITSPID = 0
SET @DistinationList = ''
-- CHECK ITPSID' S VALIDITY

SELECT@ITSPID = i.ITSPID, @DestinationID= i.DestinationID,
@BidAmount = i.BidAmount, @BidTime = i.BidTime
FROM Inserted i
INNER JOIN ITSPS ON ITSPS.ITSPID = i.ITSPID
INNER JOIN Destinations ON Destinations.DestinationID = i.DestinationID

EXEC BidAllDestinations @ITSPID,@DestinationID,@BidAmount,@BidTime, @intErrorCode = @intErrorCode output
SELECT @intErrorCode
Following should return value for @intErrorCode if any exception occures

Any one can help what is wrong with it?

Thanks

View 1 Replies View Related

Calling A Stored Procedure In A Trigger

Dec 10, 2007

Hello,

I am trying to test a simple trigger on insert and it does not work when I call EXEC sp_send_cdosysmail.
However, the stored procedures does work if I right-click on it and select Execute Stored Procedure.

Below is a simple version of the trigger I am trying to implement. I know it works in SQL Server 2000 and 2005 but can't seem to get it to work in SQL Server 2005 Express. Any help is greatly appreciated!


ALTER TRIGGER [dbo].[trig_Tableinsert]
ON [dbo].[Table]
FOR INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.

Print 'Hello'

-- Insert statements for trigger here
EXEC sp_send_cdosysmail some@one.com', 'notify@me.com','New Insert', 'test'

END

Thanks!

View 5 Replies View Related

Calling Native Code From A Trigger.

Jun 26, 2007

I've been searching for a bit but I can't seem to find a difinitive answer.



Can an SQL Server trigger call native C/C++ functions? If so, what is the mechanism?



Thanks in advance.

View 7 Replies View Related

Calling An SSIS Package From A Trigger Causes It To Run For Ever

Oct 26, 2007

hi,

when calling an SSIS package from a trigger causes it to run for ever. Know why??


In Detail;


Consider that there are two tables with the same schema in a db. Lets name that Test1 and Test2.
I develope a package whihc will transform data from Test1 to Test2. I initiate this package from a Trigger for Insert on Test1. For eg.



CREATE TRIGGER Trigger_Test1

ON Test1

AFTER INSERT

AS

BEGIN




EXEC xp_cmdshell 'dtexec /FILE "C:TestTestPackage1.dtsx"'

END


This runs for ever when a record is inserted into the Test1 table.

But, when the trigger is on someother table , everything works fine.For eg, if the trigger is on the table TT1 & this trigger initiates the same package while inserting a record into TT1, everything is fine.

Can anyone help me on this.

Thanks
Man

View 4 Replies View Related

Calling Asp.net Web Service From A Trigger Or Stored Procedure

May 6, 2008



Hi,
I need to call a webservice directly from a tigger or stored procedrue instead of creating a window service to read from a table then call the webservice .Is it possible ? if yes, please i need your support.
Thanks,

View 1 Replies View Related

Trigger Not Executing CLR Code/stored Proc

May 7, 2008

I have a database trigger that is set to call a CLR trigger/stored proc when a certain field in a table is updated. The issue is that if i execute the stored proc manually in enterprise studio, it works perfectly but the same call made through the trigger does not go through. A few more details -


I have CLR integration enabled on the sql server.

The dbo has UNSAFE ASSEMBLY rights

I have the both the assembly and the serialized dll imported in the database.


Here's the definition of the stored proc -


CREATE PROCEDURE [dbo].[WriteXMLNotification]

@TaskID [nvarchar](20)

WITH EXECUTE AS CALLER

AS

EXTERNAL NAME [DataInterfaceWebServices].[TaskUpdateXMLWriter.WriteXMLNotification].[run]



and the trigger -



CREATE TRIGGER [dbo].[tr_Task_U]

ON [dbo].[_Task]

FOR UPDATE, INSERT AS

IF UPDATE (TaskType_Status) OR UPDATE (TaskType) OR UPDATE (TaskType_SubType1)

BEGIN

SET NOCOUNT ON;

DECLARE @status AS INT

DECLARE @taskType AS INT

DECLARE @taskSubType AS INT

DECLARE @taskID as sysname

DECLARE @cmd as sysname

DECLARE @parentTask as sysname

DECLARE @NotificationXMLTaskID as sysname



SELECT @status = [TaskType_Status] FROM inserted

SELECT @taskType = [TaskType] FROM inserted

SELECT @taskSubType = [TaskType_SubType1] FROM inserted

SELECT @taskID = [TaskID] FROM inserted

SELECT @parentTask = [Parent_TaskID] FROM inserted

SELECT @NotificationXMLTaskID = [MCCTaskID] FROM _TaskNotificationXML WHERE [MCCTaskID] = @parentTask



IF (@status = 2602) AND (@taskType = 2282) AND (@taskSubType = 19500)

BEGIN

exec WriteXMLNotification @taskID;

END

ELSE IF (@taskType = 2285) AND (@parentTask IS NOT NULL) AND (@NotificationXMLTaskID IS NOT NULL)

BEGIN

exec WriteXMLNotification @parentTask;

END



END


I stepped into the trigger and it seems to execute the line " exec WriteXMLNotification @taskID;" but nothing happens, but if I run that same line manually, it works. Could it be that the impersonation by the EXECUTE AS clause is causing it to fail?

Please advise!

Thanks in Advance,
-Mihir Sonalkar.

View 1 Replies View Related

Trigger Executing Linked Server Stored Procedure

Jul 3, 2006

What is the syntax for creating a update trigger and passing the values which were updated to a stored procedure on a linked server?? Specifically need syntax for updated value, as well as the syntax for executing the stored proc on the linked server.

Thank you

View 1 Replies View Related

Trigger - Require Help For Updating A Trigger Following An INSERT On Another Table

Oct 30, 2007

Table 1





First_Name

Middle_Name

Surname


John

Ian

Lennon


Mike

Buffalo

Tyson


Tom

Finney

Jones

Table 2




ID

F

M

S

DOB


1

Athony

Harold

Wilson

24/4/67


2

Margaret

Betty

Thathcer

1/1/1808


3

John

Ian

Lennon

2/2/1979


4

Mike

Buffalo

Tyson

3/4/04


5

Tom

Finney

Jones

1/1/2000


I want to be able to create a trigger that updates table 2 when a row is inserted into table 1. However I€™m not sure how to increment the ID in table 2 or to update only the row that has been inserted.

View 17 Replies View Related







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