Create Trigger (simple Question)

Feb 12, 2004

Hi,

I'm getting this error when I try to use "inserted" table in my create trigger call.

---------------------------
Microsoft Development Environment
---------------------------
ADO error: The column prefix 'inserted' does not match with a table name or alias name used in the query.


---------------------------
OK Help
---------------------------


Could you please, help me?

Thanks,
Rovshan

View 2 Replies


ADVERTISEMENT

Create Trigger (simple Question)

Feb 12, 2004

Hi,

I'm getting this error when I try to use "inserted" table in my create trigger call.

---------------------------
Microsoft Development Environment
---------------------------
ADO error: The column prefix 'inserted' does not match with a table name or alias name used in the query.


---------------------------
OK Help
---------------------------


Could you please, help me?

Thanks,
Rovshan

View 2 Replies View Related

How To Create Simple Insert Trigger

Oct 31, 2006

I have just one table but need to create a trigger that takes place after an update on the Orders table. I need it to multiply two columns and populate the 3rd column (total cost) with the result as so:

Orders
---------

ProductPrice ProductQuantity TotalCost
-------------- ------------------ -----------
£2.50 2
£1.75 3
£12.99 2


Can anyone please help me?

View 3 Replies View Related

Simple Trigger

Feb 21, 2007

Hiim trying to implement a simple trigger, i had it working fine in oracle but am finding it difficult to convert it to the MS SQL 2005 layout.I have two tables:1) don (columns A,B,C)2) cur (columns A,B)Basically i just want to insert the value of A and B from table don into table cur after an insert.this is what i have:________________________________ALTER TRIGGER [TG_doncur] ON don AFTER INSERTAS BEGININSERT curSET A = A, B=BEND_______________________________i have an if clause aswell but i just wanna get the basics first.any help would be greatBil

View 11 Replies View Related

Simple Trigger

Mar 13, 2004

HI all,

i have a table wich contains a datetime field lastedit
i need a trigger that updates that field with the getdate() on the record that a user updated

Thanx
Cheerz Wimmo

View 4 Replies View Related

Simple Trigger Question

Aug 22, 2005

Should i create only one trigger for each table and put all the table functionality in that one trigger?

For example: tr_tblCategory, tr_tblQuestion, tr_tblAnswer

Or should i create a different trigger for each different function on that table?

For example: trReviseDate, trDoThis, trDoThat, trVerifyThis

Is there a better practice in this area?

What do you typically do?

Thanks!

View 5 Replies View Related

Trigger Simple Question

Dec 13, 2005

I am looking at a table in Microsoft SQL Server. I went to thedependencies of this table and it says TRIG_customer. so i amthinking there is a trigger that affects the table but how do i seewhat is the code that resides within this trigger. I looked among thestored procedures but i couldnt find this trigger.are all the triggers listed together somewhere. where is this triggernamed TRIG_customer?thanks in advance

View 1 Replies View Related

Simple Trigger Question

Jan 25, 2008

I do not know if I am in the proper thread, if not thnaks to let me know where to post it..

I have a runing table name CURENTALARM which strore different alarm information.
This table has a Column named STATUS.. When the new inserted rows ocurrs and STATUS =1, then I need to copy that row in a new table name STATUSLOG...

For that I have created a trigger for table CURENTALARM and then do proper commands to insert to other table.

I am using the inserted table in my trigger to fetch last inserted rows.

The question I have is that how to guaranty that each inserted row will fire the triggers properly...
What I mean is that in case I have 2 rows which gets inserted within less than a second in time interval, does the triggers will be able to do its job and proceed properly inserted row or is there a situation that when rows gets inserted too fast, the triger might miss some of them ?

If this is the case how to handl that case

thanks for your reply

regards
serge

View 2 Replies View Related

A Simple Trigger That Doesn't Work

Jan 18, 2006

Hi all, I have a problem with this trigger. It seams to be very simple, but it doesn't work...

I created a trigger on a table and I would want that this one updates a field of a table on a diffrent DB (Intranet). When I test it normally (a real situation), it doesn't work, but when I do an explicit update ("UPDATE AccesCard SET LastMove = getDate();" by example) it works.

If anyone could help me, I would appreciate.

NB: Is there a special way, in a trigger, to update a table when the table to update is on another BD ?

Francois

This is the trigger:
------------------------------------------------------------

ALTER TRIGGER UStatus
ON AccesCard
AFTER UPDATE, INSERT
AS

DECLARE @noPerson int

SET NOCOUNT OFF

IF UPDATE(LastMove)
BEGIN
SELECT @noPerson = Person FROM INSERTED
UPDATE Intranet.dbo._Users SET Intranet.dbo._Users.status = 1 WHERE personNo = @noPerson;
END

SET NOCOUNT ON

View 5 Replies View Related

Request Help Writing A Simple Trigger!

Feb 26, 2008

Experts: Please assist with coding a trigger for a SQL Server 2005 .NET application.

Here's the scenario:

Suppose there are tables MEMBERS, ACTIVITY, and HEADCOUNT that look like this:

MEMBER
member_id (int)
member_name (varchar(50))
...etc

ACTIVITY
activity_id (int)
activity_name (varchar(50))
...etc

HEADCOUNT
headcount_id (int)
member_id (int)
activity_id (int)
...etc

Suppose also that the ACTIVITY table is already populated with several records, say with activity_id = 1, 2, and 3.

OBJECTIVE: When a new member record is added to MEMBER, say member_id 10, insert one record in the HEADCOUNT table for EACH activity in ACTIVITY for that member. Thus, if member #10 is added to MEMBER, then the trigger (or some other mechanism) would add the following records to HEADCOUNT (which, say, already has 30 records):

headcount_id member_id activity_id
31 10 1
32 10 2
33 10 3

I've been advised that a trigger should do the trick for this, but as I'm totally new to SQL, I'll need some help. I'm guessing some iterating SQL command language might be required, but as I'm new to SQL, I don't know how to proceed.

Note that I'm building an ASP.NET application based on VB, and so records will be added to MEMBER through a tableadapter INSERT command. (Though I suspect this has no bearing on trigger behavior.)

Much obliged for your assistance.

-Kurt Euler
San Jose, CA

View 8 Replies View Related

Using ADO AddNew And My Simple Trigger Won't Execute

May 8, 2006

Hi,We have been using ADO and the AddNew method for a long time as a meansto add records to the database. It has always worked fine - no problem.But - we recently started using INSERT triggers that simply call a fewstored procs (they're actually SSNS stored procs that send new eventinfo to notification services). Anyway, these triggers do not seem tofire at all! If I execute an insert command manually from QueryAnalyser, no problems. But the trigger does not fire at all from myapplication!Does anyone know why this could be? For info, my connection string usedby the ADO connection object looks like this: Provider=SQLOLEDB.1;DataSource=XXX;Initial Catalog=YYYAnd my AddRecord ADO code looks like this:With rs.Open sSQL, ConnectionString, adOpenKeyset, adLockOptimistic,adCmdTable And adExecuteNoRecords.AddNewAm I mnissing something obvious here? Any help appreciated!

View 1 Replies View Related

BEGINNER: Simple Delete Trigger

Jul 6, 2006

Hello,I am trying to learn SQL Server. I need to write a trigger whichdeletes positions of the document depending on the movement type.Here's my code:set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoCREATE TRIGGER [DeleteDocument]ON [dbo].[Documents]AFTER DELETEASBEGIN-- SET NOCOUNT ON added to prevent extra result sets from-- interfering with SELECT statements.SET NOCOUNT ON;IF Documenty.Movement = 'PZ' OR Documents.Movement = 'ZW'DELETE FROM PositionsPZZWWHERE Documents.Number IN (SELECT Number FROM deleted);IF Documents.Movement = 'WZ' OR Documents.Movement = 'RW'DELETE FROM PositionsWZRWWHERE Documents.Number IN (SELECT Number FROM deleted);IF Documents.Ruch = 'MM'DELETE FROM PositionsMMWHERE Documents.Number IN (SELECT Number FROM deleted);ENDUnfortunatelly I receive errors which I don't understand:Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 12The multi-part identifier "Documents.Movement" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 12The multi-part identifier "Documents.Movement" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 13The multi-part identifier "Documents.Numer" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 15The multi-part identifier "Documents.Movement" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 15The multi-part identifier "Documents.Movement" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 16The multi-part identifier "Documents.Number" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 18The multi-part identifier "Documents.Movement" could not be bound.Msg 4104, Level 16, State 1, Procedure DeleteDocument, Line 19The multi-part identifier "Dokuments.Number" could not be bound.Please help to correct the code.Thank you very much!/RAM/

View 10 Replies View Related

Creating A Simple Update Trigger

Jul 20, 2005

I am extremely new at SQL Server2000 and t-sql and I'm looking tocreate a simple trigger. For explanation sake, let's say I have 3columns in one table ... Col_1, Col_2 and Col_3. The data type forCol_1 and Col_2 are bit and Col_3 is char. I want to set a trigger onCol_2 to compare Col_1 to Col_2 when Col_2 is updated and if they'rethe same, set the value on Col_3 to "Completed". Can someone pleasehelp me?Thanks,Justin

View 7 Replies View Related

How To Create New CLR Trigger From Existing T-Sql Trigger

Mar 18, 2008

how to create new CLR trigger from existing T-Sql Trigger Thanks  in advance

View 3 Replies View Related

Simple Trigger For SQL Server Express 2005

Jun 12, 2008

I've this tableCREATE TABLE [dbo].[Attivita]( [IDAttivita] [int] IDENTITY(1,1) NOT NULL, [IDOwner] [int] NULL, [IDAttivitaStato] [varchar](1) COLLATE Latin1_General_CI_AS NULL, [IDAttivitaTipo] [varchar](2) COLLATE Latin1_General_CI_AS NULL, [IDAnagrafica] [int] NULL, [Data] [datetime] NULL CONSTRAINT [DF_Attivita_Data] DEFAULT (getdate()), [Descrizione] [varchar](max) COLLATE Latin1_General_CI_AS NULL, [Privato] [bit] NULL, [LastUpdate] [datetime] NULL CONSTRAINT [DF_Attivita_LastUpdate] DEFAULT (getdate()), CONSTRAINT [PK_Attivita] PRIMARY KEY CLUSTERED ( [IDAttivita] ASC)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]How Can I create a trigger for modify the IDAttività Stato field in specific situaion: if IDAttivitaTipo ==  OK or  == NOIDAttivitaStato must be set to CPlease note that I can write in the IDAttivitaStato field (during my code operation).... but I would like also automatic update if the IDAttivitaTipo is OK or NO Can you help me for create this with a trigger?Thanks 

View 2 Replies View Related

Transact SQL :: Simple Trigger To Audit Who When Is Changing A Specific Column

Jul 6, 2015

I need a trigger to know who and when a char(1) column is changed.  Would like to write the audit trail to its own table I can query and record before and after values.

DDL:

CREATE TABLE [dbo].[Test](
[Customer] [varchar](12) NULL,
[Active] [char](1) NULL DEFAULT ('N') --Must use char 1 b/c more than 2 possible values
)

Insert into Test (Customer, Active) Values ('Acme','Y')..I want trigger to tell me whowhenwhere this value was changed.  If using sql auth capture client windows id if possible and write to audit table Update Test set Active = 'N'

View 6 Replies View Related

Create A Simple Table

Feb 6, 2008

i realize this is a basic question, but i'd like advise on the best way to create a table to store financial time series data. i already have a table to store securityid which is the primary key. However, when i move over to the table to store time series, i will have many secid as well as different dates and types of data. what should my primary key-autonumbered or concatenated from secid and date etc...in addition, i want to have a good way to query the table to make sure there are no dupes (same secid and same data etc). many thanks

View 1 Replies View Related

Create To Simple Reports

Jun 25, 2007

Hey Everyone,



I am new to SQL 2005 and Reports. How can I create an automated weekly report for a database to show Disk usage and top 10 tables. I am after to something similar to the Summary report in SQL 2005. Advantage would be to have it email as well.



Cheers,



Mark Bayliss

View 2 Replies View Related

How To Create This Simple Database Search? Thank You.

Dec 7, 2004

Hello,

I have a search form in an ASP.NET/VB page. The form has the input text box and the button "search". The keywords are passed in the URL to results.aspx.

Here is an example of what I get in the URL, when I write the keywords "asp", "book" and "london" in the input text box and click "search":
results.aspx?search=asp%20book%20london

The database table has 3 fields: "id", "title" and "description".

I want to display all the records where at least one of the keywords is found in any of the 2 fields "title" and "description".

1. I suppose I need to get the words out of the URL to be used by SQL.
Maybe: string[] searchString = request.queryString("search").split('search'); ???
How can i make this run when page loads? I supose i need it. Right?

2. How should the SQL look? I supose i need to use the "Like" command
SELECT * FROM books WHERE title LIKE ...
But how to I use it if I can have 1, 2, 3, ... keywords?

Can someone help me?

Thanks,
Miguel

View 1 Replies View Related

How Can I Automatic Create All That Objects In Assembly In Simple Way ??

Jan 12, 2006

Hi
 
I use SQL code snippet to attach the CLR assembly (dll) to the SQL Server Express
 
CREATE ASSEMBLY [DatabaseAndImages]
AUTHORIZATION [dbo]
FROM 'C:CLR_File.dll'
WITH PERMISSION_SET = SAFE
 
That file content CRL Codes for 10 Stored Procedures & 3 UDT & 5 Functions & 6 Triggers
As you can see it's content large amount of DB objects !!
 
My Question is ..
Is there any simple way can I use it to extract or automatic create all that Objects in the Database without use separate SQL Statement for each one ??
 
By Example , I will use this SQL statement to create the sp_AddImage that already located inside the CLR dll file
 
CREATE PROCEDURE [dbo].[sp_AddImage]
       @ImageID [uniqueidentifier],
       @ImageFileName [nvarchar](max),
       @Image [varbinary](max)
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [DatabaseAndImages].[StoredProcedures].[sp_AddImage]
 
 
But as you know .. I have many objects .. and I am in development phase and I will do change to that object many time and also may I will add much more €¦
 
I thing it's not good to write SQL Statement for each object and do changes every time when I change the object definition
 
Is there any one line of SQL statement can I use it to automatically create and extract all the objects inside the assembly ??
Or is there any way to do that Issue by simple operation ??
 
 
And thanks with my best regarding
Fraas

View 3 Replies View Related

Simple Query To Create Column Of Sequential Numbers

May 2, 2006

Hi,
Can anyone tell me offhand the simplest/most elegant way of updating an integer column to a sequential column of numbers with a query?

e.g given

intval | Description| Cost
0 | Descvalue0| 4.32
2 | Descvalue2| 4.33
3 | Descvalue3| 4.34
8 | Descvalue8| 4.35

change it to:

intval | Description| Cost
0 | Descvalue0| 4.32
1 | Descvalue2| 4.33
2 | Descvalue3| 4.34
3 | Descvalue8| 4.35

I think it might need a stored proc..

Many Thanks
greg

View 2 Replies View Related

Combine And Convert Int Fields To Create One Field, Should Be Simple

Oct 19, 2007

I want to combine two of my fields somewhat like when you combine to char fields and concatenate them. But these two fields are int. How do i do that? Here's my query right now:




Code Block
SELECT AutoID,
CONVERT(Varchar(Mars_Calender_Year )+ CONVERT(Varchar(Mars_Calender_Period_Code) as MarsId
FROM NavisionReplication.dbo.Tbl_Mars_Calender
ORDER BY Mars_Calender_Year DESC








what am i doing wrong?

View 5 Replies View Related

Very Simple Question: Cannot Create Table With Identity Fields Using SQL Sentences

Jan 26, 2007

Hi, I'm trying to build a several tables using sql ce 3.1
I refer to the manual on Create Table:
ms-help://MS.SSCE.v31.EN/ssmprog3/html/143cad25-5c1d-4c96-bd8b-6a95dbfb1b00.htm

The sample:
CREATE TABLE MyCustomers (CustID int IDENTITY (100,1) PRIMARY KEY,
CompanyName nvarchar (50))

just simply doesn't work displaying this error:

SQL Execution Error
Executed statement: CREATE TABLE MyCustomers (CustID int IDENTITY (100,1) PRIMARY KEY,
CompanyName nvarchar (50))

Error Source: SQL Server Compact Edition ADO.Net Data Provider
Error Message: There was an error parsing the query. [Token line number =1,
Token line offset 40, Token in error=IDENTITY]


I tested against a SQL Desktop, everything is OK.
What's wrong with the sentence?
Please some advise or workaround will be appreciated
Thanks
MSCD Fernando Zorrilla de San Martín

View 4 Replies View Related

Create Trigger Help?

Sep 14, 2004

I have a table that has a number of data fields,I need to be able to capture datatime when the date field was entered or entered value changed.I was told I need to create a trigger on that table that contains all the fields.

I have seen the syntax for creating triggers, and read some documentation but I am still in the dark as how to create what I need to.

I was hoping to see if somebody had a similar example or an advice, anything is more than what I have at the moment.


CREATE TRIGGER NotifyDateFieldUpdates
ON RelocateeRemovalist
For INSERT, UPDATE, DELETE
AS
DECLARE @RemovalistNumber VARCHAR(200)
DECLARE @RelocateID INT

/*InspectionDate */
DECLARE getInsp CURSOR FOR SELECT RelocateID,RemovalistNumber
FROM INSERTED a LEFT JOIN DELETED b ON (a.RemovalistNumber=b.RemovalistNumber and a.RelocateID=b.RelocateID)
WHERE a.InspectionDate IS NOT NULL AND b.InspectionDate IS NULL

OPEN getInsp

FETCH NEXT FROM getInsp INTO @RelocateID, @RemovalistNumber
WHILE (@@FETCH_STATUS <> -1)
BEGIN
INSERT INTO RelocateeRemovalistFieldEntry(RElocateID, RemovalistID)SELECT
RelocateID,RemovalistID FROM INSERTED a LEFT JOIN RelocateeRemovalistFieldEntry b ON
(a.RelocateID=b.RelocateID AND a.RemovalistNumber=b.RemovalistNumber)WHERE b.RElocateID is null


UPDATE RelocateeRemovalistFieldEntry SET InspectionDateDateTime=GETDATE()
WHERE RelocateID=@RelocateID aND RemovalistNumber=@RemovalistNumber

FETCH NEXT FROM getInsp INTO @RelocateID, @RemovalistNumber
END

DEALLOCATE getInsp

GO

This is what I was able to come up with so far,but when i check the syntax it gives me an error "Ambiguous column name "RelocateID" and "Ambiguous column name "RemovalistNumber" I don't know what is it trying to tell me here and couldn't find much help.

Regards and thanks

View 8 Replies View Related

Create Trigger Help

May 9, 2008

i do have my 'Product' TABLE IN DATABASE 'ABC'

Product TABLE OUTPUT

PRODUCT_CODE PRODUCT_TYPE PRODUCT_DESCPRODUCT_ID PRODUCT_GROUP_CODE
6001 computer NULL ENVD14
6002 keyboard NULL ENVD14
6003 mouse NULL ENVD14
6004 cables NULL ENVD14
6005 processor NULL ENVD14

AND 'Product_Mst' TABLE IN DATABASE 'XYZ'

Product_Mst OUTPUT

PROD_CODE Prod_Ver PROD_TYPE PROD_DESC PROD_ID PROD_GRP_CODE
6001 0 computer NULL ENVD 14
6002 0 keyboard NULL ENVD 14
6003 0 mouse NULL ENVD 14
6004 0 cables NULL ENVD 14
6005 0 processor NULL ENVD 14

Now i want TO CREATE TRIGGER such that every updation in Product TABLE will UPDATE the appropriate record IN Product_Mst

FOR example IF i fire below query IN ABC Database

UPDATE Product
SET PRODUCT_DESC = 'Available' WHERE Product_Code = 6001

Then the OUTPUT OF the Product_Mst shoub be..

Product_Mst OUTPUT

PROD_CODE Prod_Ver PROD_TYPE PROD_DESC PROD_ID PROD_GRP_CODE
6001 0 computer NULL ENVD 14
6001 1 computer NULL ENVD 14
6002 0 keyboard NULL ENVD 14
6003 0 mouse NULL ENVD 14
6004 0 cables NULL ENVD 14
6005 0 processor NULL ENVD 14

Means i want to increment the version by 1 and Insert that records into Product_Mst Table at every updation.

I hope i am clear with my question.

Regards
Prashant Hirani

View 1 Replies View Related

How To Create DML Trigger

Jan 6, 2015

We have Tables like parent and Child Table.Like we have Child Table as Name AcademyContacts,In that we have Columns like

Guid(PK)Not Null,
AcademyId(FK), Not Null,
Name,Null
WorkPhone,Null
CellPhone,Null
Email Id,Null
Other.Null

Since we have given Null to ''Workphone'',''Cellphone '', ''Email ID''.when inserting the data into these table.if the particular columns are empty while inserting also the data will get populate into the table.And.I need is if these columns are ''Workphone'',''Cellphone'' , ''Email ID'' they cant insert the data into table.

Like it must trigger like ''Please enter atleast one of these ''Workphone'',''Cellphone'' , ''Email ID'' columns.

View 4 Replies View Related

Help Me Create This Trigger

Jul 20, 2005

Hi everybody,How can I Update a field from another table by Trigger? Can someone sendme the statment to do it?I have a table called Clients with fields : ID_Clients, ClientAnd Another called Doc with fields : ID_Doc, ID_Clients, ClientThese tables are in different databases and I would like to esure theintegrity by add a Trigger to update in Doc´s table the field Clienteverytime it´s changed in the Client´s table.Thanks for Attetion.Leonardo Almeida*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 1 Replies View Related

HOW TO CREATE TRIGGER ?

Jul 20, 2005

Hii have 2 Tablefirst one : Customerwith 4 Fields : cst_no,cst_name,total_Debit,tot_creditsecond one : Transactionwith 5 Fields : Trns_no,Trns_Date,cst_no,debit,creditMY QUESTION:HOW TO CREATE TRIGGER FOR UPDATE TOT_DEBIT AND TOT_CREDIT FILEDS INCUSTOMER TABLE FROM Transaction TABLEThank you

View 4 Replies View Related

Create A Trigger Through C#/.NET

Jan 10, 2008

Hi folks,

I have created a trigger that I can enter and works great from the sqlcmd terminal. When I try to submit the same query in a .NET project I get an error that "Create Trigger must be the first statement in a batch". The Create trigger is submitted by itself through the sqlcommand.executenonquery() method.

I am trying to create a database for a project but the only thing that I can't seem to get working is submitting this trigger.

Appreciate any help.

Dave

View 5 Replies View Related

Help To Create Trigger

May 10, 2008

I am trying to create a trigger to help me get a the time duration but this is not working.






Code Snippet

CREATE TRIGGER Duratn

ON dbo.CONTACTS
AFTER INSERT, UPDATE, DELETE
AS
SET NOCOUNT ON
UPDATE dbo.CONTACTS
SET Duratn = (DATEDIFF(CallStartTime) - DATEDIFF(CallFinishTime))



My table is as follows:

No Caller CallStartTime CallFinishTime Duratn

10000 John 10/05/2008 18:13:00 10/05/2008 18:14:00 NULL

View 13 Replies View Related

Trigger. How To Create?

Oct 4, 2007

What I was trying to use to create the trigger was the same code I would use on Sql Server Express:

cmd.CommandText = "CREATE Trigger [contactsLastUpdate] on [contacts] for Insert, Update " +
"AS " +
"Begin " +
"SET NOCOUNT ON " +
"Update t " +
"set syncLastUpdate = GetDate() " +
"From contacts t " +
"Join inserted i " +
"On t.id = i.id " +
"SET NOCOUNT OFF " +
"End"; +

But I get an error message:

"There was an error parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = Trigger ]"

How do you guys create Triggers on SQL Server CE (2005)?

Thanks

View 3 Replies View Related

Help! Trying To Create A Trigger In SQL 2000...

Jun 18, 2007

Hello All!
I am trying to create a trigger that upon insertion into my table an email will be sent to that that recipeinent with a image attached ( like a coupon)That comes from a different table, problem is, It will not allow me to send the email ( using xp_sendmail) with the coupon attached. I am using varbinary for the coupon and nvarchar for the rest to be sent, I get an error that Invaild operator for data type. operator equals add, type equals varchar.
Looks basically like this(This is my test tables):
CREATE TRIGGER EileenTest ON OrgCouponTestMainFOR InsertAS declare @emailaddress varchar(50)declare @body varchar(300)declare @fname varchar(50)declare @coupon varbinary(4000)
if update(emailaddress)begin
Select             @emailaddress=(select EmailAddress from OrgCouponTestMain as str),            @fname=(select EmailAddress from OrgCouponTestMain as str)            @Coupon=(select OrgCoupon1 from OrgCouponTest2 as image)
 
SET @body=  'Thank you' +' '+ @fname +' '+ ',Here is the coupon you requested' +'  ' + @couponexec master.dbo.xp_sendmail            @recipients = @emailaddress,            @subject = 'Coupon',           @message = @bodyEND

View 6 Replies View Related

Error On Create Trigger

Oct 21, 2004

I have the following
CREATE TRIGGER dbo.tgrCacheCustomers
ON dbo.Customers
FOR INSERT, UPDATE, DELETE
AS
EXEC sp_makewebtask 'C:DependencyFile.txt','SELECT top 1 CustomerId FROM customers'
and I get the following error that I dont understand:

Error 21037: [SQL-DMO] The name specified in the Text property's 'CREATE ...' statement must match the Name property, and must be followed by valid TSQL statements.

Any ideas someone?

View 2 Replies View Related







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