Re: Triggers, truncate field, how to

From: Gregory A. Larsen (greg.larsen_at_netzero.com)
Date: 05/20/04


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


Relevant Pages

  • text editor component (seeking design advice)
    ... TEXT FOLDING ... i do not know how to store the character data. ... i'll have to parse even the folded text - for syntax highlighting ...
    (alt.comp.lang.borland-delphi)
  • Re: The fallacy of strengthened liars paradox.
    ... have the same syntax. ... However, in English, the same expression, character ... no real difference. ... What does it mean to me to have contradictory ...
    (sci.logic)
  • Re: This MI5 guy and message rules
    ... I just want to parse on the letters M I and 5. ... However, and true to OE, sometimes OE does *not* use ALL "words" when deciding to trigger the rule. ... which would trigger on the character operands: ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Most pythonic way to truncate unicode?
    ... I don't want to accidentally chop any unicode characters in half. ... If the byte truncate length would normally cut a unicode character in ... 2, then I just want to drop the whole character, not leave an orphaned ... pos = maxlen - 1 ...
    (comp.lang.python)
  • Re: Again: Please hear my plea: print without softspace
    ... >> character instead of a ',' to alter the behavior of print. ... Changing the behavior of print when a syntax ... print statement is a sort of magic syntax as it is; ... it could be some other character. ...
    (comp.lang.python)

Loading