Friday, February 24, 2012

Allowing truncation of data on insert

I am using SQL 2000. Is there a DB option that will allow an insert to successfully complete even though the data will be truncated in some of the fields?try this...

set ansi_warnings off
create table #tmp(f1 varchar(1))
insert into #tmp values ('!')
insert into #tmp values ('!!')
select * from #tmp
drop table #tmp
go
set ansi_warnings on
create table #tmp(f1 varchar(1))
insert into #tmp values ('!')
insert into #tmp values ('!!')
select * from #tmp
drop table #tmp
go|||Another approach is to ensure the data is truncated when you insert it by explicitly truncating it yourself.

Eg INSERT INTO myTable (myColName)
VALUES(CAST('abcdefg' AS varchar(4)))

No comments:

Post a Comment