The disable varbinary truncation configuration parameter controls whether trailing zeros are included at the end of varbinary and binary null data.
By default, disable varbinary truncation is off for the server.
create table test1(col1 varbinary(5))
insert into test1 values(0x12345600)
select * from test1
col1 ------------ 0x123456
select * from test1
col1 ------------ 0x12345600
SAP ASE considers data with or without trailing zeros as equal for comparisons (that is, 0x1234 is the same as 0x123400).
sp_configure "disable varbinary truncation", 1 select * into test2 from test1
insert into test2 select * from test1
select * from test2
col1 ------------ 0x12345600 0x12345600
Bulk copy (bcp) inserts data according to how disable varbinary truncation is set on the column when created.
You cannot use alter table to change the truncation behavior for a specific column. However, columns you add with alter table either truncate or preserve trailing zeros according to the value of disable varbinary truncation.
sp_configure "disable varbinary truncation", 1 create table test3(c1 varbinary(5)) insert into test3 values(0x123400)
select * from test3 c1 ---------- 0x123400
However, if you enable truncated trailing zeros and use alter table to add a new column, c2:
sp_configure "disable varbinary truncation", 0 alter table test3 add c2 varbinary(5) null insert into test3 values(0x123400, 0x123400)
select * from test3 c1 c2 ---------- ---------- 0x123400 NULL 0x123400 0x1234
select 0x12345600 union select 0x123456 ------------- 0x12345600 select 0x123456 union select 0x12345600 ------------- 0x123456
select 0x12345600 + col1, col1 from test1
col1 -------------------- ------------ 0x123456001234560000 0x1234560000 0x1234560001234560 0x01234560 0x1234560012345600 0x12345600 0x123456000123456700 0x0123456700
select bintostr(0x12340000)
------------ 1234000
select col1 from (select 0x123456 col1 union all select 0x12345600 col1) temp1 order by col1
col1 ---------- 0x123456 0x12345600
Subqueries – trailing zeros are preserved unless the query involves a worktable, in which case the truncation depends on the value of disable varbinary truncation.
Dumps and loads – if the table data you dump includes trailing zeros, the trailing zeros are preserved when you load that data, regardless of the value of disable varbinary truncation in the target database.
Unions (see example for worktables, above).
select convert(binary(5), 0x0000001000) ------------ 0x0000001000