sql - How can I compare the trimmed and untrimmed lengths of fields without retyping the field name? -
basically, want check if there spaces right of text in varchar field. so, want compare datalength(fieldname)
datalength(rtrim(fieldname))
.
this isn’t hard.
only thing is, need varchar fields in 5 tables. comes out 250 fields need compare way. there way can put field names 1 query without typing each one’s name 2x?
i'm using query names of fields need at.
select name sys.columns object_id = (select object_id sys.tables name='tablename') , system_type_id = 167
(using sql server 2005)
thanks!
i let sql server generate code me if it's typing problem:
select 'select * ' + o.name + ' datalength(' + c.name + ') > datalength(rtrim(' + c.name + '))' sys.objects o inner join sys.columns c on c.object_id = o.object_id , c.system_type_id = 167 o.name = 'tablename'
are sure type 167 need check though?
Comments
Post a Comment