January 20th, 2004, 02:13 AM
Join Date: Jan 2004
Time spent in forums: 16 m 52 sec
Reputation Power: 10
| One reason this will not work is because TSQL variables are strong typed. You would error out if you attempted this with a date or number variable. |
Another reason is MS-SQL has no concept of arrays. You would have to use cursors and it would be slow and ugly, and like victor pointed out you would run into issues with strongly typed columns.
If you are using varchar fields they will be automatically trimmed. If you are using char fields they will contain leading and trailing spaces.
If you are storing variable width data use a varchar and trim it on the way in through a sproc. Then you do not need to trim them on the way out. Otherwise just trim the columns on the way out in a select..
select ltrim(rtrim( nme ) ) from dbo.fooBar where id = 1
You can also update a table and trim the values, however this will do no good if they are stored type char.
create table fooBar(
id int identity(1,1) primary key,
stat varchar(10) check (stat IN('Retired', 'Playing', 'Injured') ),
create procedure insert_foobar( @stat varchar(10), @nme varchar(10), @foo int )
insert into dbo.fooBar ( stat, nme, foo ) values( ltrim(rtrim(@stat)), ltrim(rtrim(@nme)), @foo )
Last edited by abombss : January 20th, 2004 at 02:20 AM.