Monday, March 19, 2012
Controlling Updated fields on trigger
I Update myField1 of myTable in the trigger but not in the query that starts
the trigger.
Then i check if UPDATE(myField1). This is true or false?
CREATE TRIGGER tr_MyTable ON dbo.MyTable
FOR INSERT, UPDATE, DELETE
AS
...
UPDATE myTable SET myField1 = 'XYZ' WHERE ...
...
if update(myField1 ) /* IS TRUE OR FALSE ' */
begin
..
endFalse.
The UPDATE( ) clause comes from the state of the data that fired the
trigger, not from any manipulations inside the trigger.
Also, FWIW, if your update sets a column to the same value it had before the
update, that will also be considered an updated column. (Since I did not
find the clause useful, I stopped using it. If it is smarter in 2000,
someone should know.)
RLF
"checcouno" <checcouno@.discussions.microsoft.com> wrote in message
news:9B1547D0-05DA-438B-947D-8DFDA29FE77A@.microsoft.com...
> In myTable i've got a trigger for INSERT, UPDATE, DELETE
> I Update myField1 of myTable in the trigger but not in the query that
> starts
> the trigger.
> Then i check if UPDATE(myField1). This is true or false?
> CREATE TRIGGER tr_MyTable ON dbo.MyTable
> FOR INSERT, UPDATE, DELETE
> AS
> ...
> UPDATE myTable SET myField1 = 'XYZ' WHERE ...
> ...
> if update(myField1 ) /* IS TRUE OR FALSE ' */
> begin
> ...
> end
>|||Russell Fields (RussellFields@.NoMailPlease.Com) writes:
> Also, FWIW, if your update sets a column to the same value it had before
> the update, that will also be considered an updated column. (Since I
> did not find the clause useful, I stopped using it. If it is smarter in
> 2000, someone should know.)
I have not tried it, but there is no reason to expect it to be smart.
If you update 1000 rows, and one of them changes value, what should IF
UDPATE return?
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx
Friday, February 24, 2012
CONTAINS and wildcard
Select * from myTable where contains (Col1, 'Africa') or (Col2, 'Africa')
Also, I tried this, didn't return anything:
Select * from myTable where contains (Col1, 'Africa*') or (Col2, 'Africa')
Both Col1 and Col2 has the string 'Africa' and 'African' in it.
--sharifOn Oct 29, 8:59 pm, Sharif Islam <mis...@.npspam.uiuc.eduwrote:
Quote:
Originally Posted by
Is it a good idea to have multiple contains? I have this query:
>
Select * from myTable where contains (Col1, 'Africa') or (Col2, 'Africa')
>
Also, I tried this, didn't return anything:
>
Select * from myTable where contains (Col1, 'Africa*') or (Col2, 'Africa')
>
Both Col1 and Col2 has the string 'Africa' and 'African' in it.
>
--sharif
Hi Sharif,
What version of SQL Server are you using? What is the error message
you are getting? Is the table configured for Full-Text Indexing?
Also - your syntax for the CONTAINS statement is incorrect. Try:
SELECT *
FROM myTable
WHERE CONTAINS(Col1, '"Africa*"')
OR CONTAINS(Col2, '"Africa*"')
Good luck!
J|||jhofmeyr@.googlemail.com wrote:
Quote:
Originally Posted by
On Oct 29, 8:59 pm, Sharif Islam <mis...@.npspam.uiuc.eduwrote:
Quote:
Originally Posted by
>Is it a good idea to have multiple contains? I have this query:
>>
>Select * from myTable where contains (Col1, 'Africa') or (Col2, 'Africa')
>>
>Also, I tried this, didn't return anything:
>>
>Select * from myTable where contains (Col1, 'Africa*') or (Col2, 'Africa')
>>
>Both Col1 and Col2 has the string 'Africa' and 'African' in it.
>>
>--sharif
>
Hi Sharif,
>
What version of SQL Server are you using? What is the error message
you are getting? Is the table configured for Full-Text Indexing?
>
Also - your syntax for the CONTAINS statement is incorrect. Try:
SELECT *
FROM myTable
WHERE CONTAINS(Col1, '"Africa*"')
OR CONTAINS(Col2, '"Africa*"')
ah, that was it, thanks!
--sharif