Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 TRIM data upon insert into table?

Author  Topic 

Goalie35
Yak Posting Veteran

81 Posts

Posted - 2010-08-25 : 15:48:26
I have a table that's receiving data from multiple applications, some applications of which I don't have access to the source code/insert queries. My problem though is some of these applications are including leading/trailing spaces on certain string values.

Is there a way within sql server, to specify that I want any values that are inserted into a particular field to be trimmed or can I only specify this within the actual insert query? Like for example, I can specify a default value of "GETDATE()" for a datetime field if a null value is inserted. Can I specify a TRIM function if spaces are present?

Thanks.

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2010-08-25 : 15:52:20
You can use a trigger on insert to update the inserted records to trim, or better you should use a stored procedure for your inserts and write the code to trim in there.


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page
   

- Advertisement -