Re: Triggers, truncate field, how to
From: Gregory A. Larsen (greg.larsen_at_netzero.com)
Date: 05/20/04
- Next message: George Hester: "Error in sample Northwind?"
- Previous message: Adam Machanic: "Re: How to store PDFs and photos in the database?"
- In reply to: Carlos Aguero: "Triggers, truncate field, how to"
- Next in thread: Francisco: "RE: Triggers, truncate field, how to"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 May 2004 09:01:03 -0700
The len() function is the correct function to find the length of a character
column. But I am wondering why you would want to truncate the column to only
25 characters, when I'm guessing the column definition is greater than 25?
If that is really what you want to do then you will need to use the
substring function like so, becauase there is no "truncate" function in for
T-SQL.
declare @c varchar(100)
set @c = 'Need to set the variable to a very long string so it can be
truncted.'
print len(@c)
if len(@c) > 25
set @c = substring(@c,1,25)
print @c
-- ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- ---- Need SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples "Carlos Aguero" <carlos986@hotmail.com> wrote in message news:37E67671-0029-426B-BF76-E1F5FC40C1E4@microsoft.com... > Hi, > I am a little new to SQL Server (specially writing triggers). I need to check the length of fields before inserting or updating a field, but I don't know where to find the wright syntax code for it. This is what I want my trigger to do logically. > > CREATE TRIGGER checkfield ON table1 > FOR INSERT, UPDATE > AS > IF Len(table1.DelNurse) > 25 then > Truncate(DelNurse,25) > > This is what I want it to do. I don't know how to write the right syntax for this. Please I would appreciate any help on this. Is there any site where I can find syntax or examples for that kind of problems? > Thanks > Carlos
- Next message: George Hester: "Error in sample Northwind?"
- Previous message: Adam Machanic: "Re: How to store PDFs and photos in the database?"
- In reply to: Carlos Aguero: "Triggers, truncate field, how to"
- Next in thread: Francisco: "RE: Triggers, truncate field, how to"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading