Storing as char but rather have varchar behavior


there char(2) - char(5) fields in our database (sql2008 sp2). when applications work data spaces stored in char columns creating difficulties. there way store data in char columns when retrieve them sql server returned them rtrimmed similar varchar behavior without adding views etc database. similar "set ansi_nulls" behavior nulls when set null equal null or so.

if database level setting set once awesome.

if not considering rebuild our tables varchar columns , deal performance impact.

thank you


gokhan varol

hi gokhan,

it seems not available trim data char data type varchar. this, may need convert data specified length manually:

declare @myvariable varchar(5) = 'abc'; declare @mynextvariable char(5) = 'abc'; select datalength(@myvariable) 'myvariable', datalength(@mynextvariable) 'mynextvariable',datalength(cast(@mynextvariable varchar(3))) 'convertlength'

if not acceptable way, may consider using varchar data type instead of char.


technet subscriber support
if technet subscription user , have feedback on our support quality, please send feedback here.


stephanie lv

technet community support



SQL Server  >  SQL Server Database Engine



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........