Link to home
Start Free TrialLog in
Avatar of jspc
jspcFlag for Australia

asked on

Trigger for SQL Server 2008

I was provided with a SQL Trigger yesterday by one of your members which works.

I have since discovered the program which inserts the data has a bug whereby it's creating a carriage return and a space before the data.

I was wondering if l can include in the below trigger script a workaround, whereby it removes the left space and carriage return first before the update?

The data type is TEXT. I'm not sure why the developer of the database is using TEXT.

Thanks


CREATE TRIGGER TRANSHEADERS_CustomerRef_Update  
ON Transheaders  
FOR INSERT AS  
BEGIN  
    UPDATE TRANSHEADERS
Set ZCustomerRef = ExtraText
Where AccountID = 'CAWWWEBXXXX'
Avatar of harisrashid
harisrashid
Flag of Denmark image

Use LTRIm function to remove spaces and Replace function to remove other characters.
Avatar of jspc

ASKER

Are you able to provide the required script, please?
Just a comment:

Get rid of TEXT. It is deprecated. Also some string functions done work on TEXT, which requires an additional CAST(column TO [N]VARCHAR(MAX)). This is should not be done without very good reasons. And not knowing why it is used is definitly not a good reason.
Avatar of jspc

ASKER

I can only work with what I have. I cant change the data type of the database.
Are you suggesting adding more detail to the script, converting it? I don't understand what you mean by CAST.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial