可以呀, declare @re varchar(34) select @re=A0 from <table>
是不是這個意思?? Create Table A(A0 Varchar(5)) Insert A Select 'AAAAA' Union All Select 'BB' Union All Select 'CCC' Union All Select 'DDDDD' GO Select * From A Where Len(A0)=5 GO Drop Table A /* A0 AAAAA DDDDD */
select * from table where len(isnull(A0,'')) = 34这样就可以啊
如果创建表的时候没有ansi_padding on,出现的空格是不是都没办法计算在字符串的长度内?
len(isnull(A0,'')) 這個判斷沒有必要加
Select * From TableName Where datalength(A0)=34
Create Table A(A0 Varchar(5)) Insert A Select 'AAAAA' Union All Select 'BB' Union All Select 'CCC' Union All Select 'DDDDD' Union All Select Null GO Select * From A Where Len(A0)=5 Select * From A Where DataLength(A0)=5 GO Drop Table A /* A0 AAAAA DDDDD */具體是第一個還是第二個,你自己取捨吧。不過感覺上應該不是第二個,所以之前沒寫出來。
declare @re varchar(34)
select @re=A0 from <table>
Create Table A(A0 Varchar(5))
Insert A Select 'AAAAA'
Union All Select 'BB'
Union All Select 'CCC'
Union All Select 'DDDDD'
GO
Select * From A Where Len(A0)=5
GO
Drop Table A
/*
A0
AAAAA
DDDDD
*/
where len(isnull(A0,'')) = 34这样就可以啊
Insert A Select 'AAAAA'
Union All Select 'BB'
Union All Select 'CCC'
Union All Select 'DDDDD'
Union All Select Null
GO
Select * From A Where Len(A0)=5
Select * From A Where DataLength(A0)=5
GO
Drop Table A
/*
A0
AAAAA
DDDDD
*/具體是第一個還是第二個,你自己取捨吧。不過感覺上應該不是第二個,所以之前沒寫出來。