我有SQL规则,它检查从数字开始的字符串。我有一些非英语数字,我已经包含了一个条件。
当我将sql查询存储为行中的字符串时显示?而是信件
column数据类型为nvarchar,collation为SQL_Latin1_General_CP1_CI_AS
SELECT * Table Name WHERE (LEFT(RESELLER_CITY_NM,1) LIKE ''[0-9]'') or left(RESELLER_CITY_NM,1) in (N''一'',N''二'',N''三'',N''四'',N''五'',N''六'',N''七'',N''八'',N''九'',N''十'',N''零'',N''两'',N''千'',N''万'',N''億'',N''一つ'',N''二つ'',N''三つ'',N''四つ'',N''五つ'',N''六つ'',N''七つ'',N''八つ'',N''九つ'',N''十'',N''일'',N''이'',N''삼'',N''사'',N''오'',N''육'',N''칠'',N''팔'',N''구'',N''십'',N''백'',N''천'',N''만'',N''일억'',N''십억'',N''백억'',N''один'',N''два'',N''три'',N''четыре'',N''пять'',N''шесть'',N''семь'',N''восемь'',N''девять'',N''десять'',N''ноль'',N''сто'',N''тысяча'',N''миллиард'',N''миллион'')
SELECT * Table Name WHERE (LEFT(RESELLER_CITY_NM,1) LIKE ''[0-9]'') or left(RESELLER_CITY_NM,1) in (N''一'',N''二'',N''三'',N''四'',N''五'',N''六'',N''七'',N''八'',N''九'',N''十'',N''零'',N''两'',N''千'',N''万'',N''億'',N''一つ'',N''二つ'',N''三つ'',N''四つ'',N''五つ'',N''六つ'',N''七つ'',N''八つ'',N''九つ'',N''十'',N''일'',N''이'',N''삼'',N''사'',N''오'',N''육'',N''칠'',N''팔'',N''구'',N''십'',N''백'',N''천'',N''만'',N''일억'',N''십억'',N''백억'',N''один'',N''два'',N''три'',N''четыре'',N''пять'',N''шесть'',N''семь'',N''восемь'',N''девять'',N''десять'',N''ноль'',N''сто'',N''тысяча'',N''миллиард'',N''миллион'')```
Output:
SELECT * from table A with (nolock) WHERE (LEFT(RESELLER_CITY_NM,1) LIKE '[0-9]') or left(RESELLER_CITY_NM,1) in (N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'??',N'??',N'??',N'??',N'??',N'??',N'??',N'??',N'??',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'?',N'??',N'??',N'??',N'????',N'???',N'???',N'??????',N'????',N'?????',N'????',N'??????',N'??????',N'??????',N'????',N'???',N'??????',N'????????',N'???????')
我怀疑这是一个动态查询。也许你的City
字段是nvarchar
,但我想你将你的查询存储在varchar
中。或者你在字符串常量的开头缺少N
。这是一个例子。
declare @T nvarchar(1000);
declare @Q nvarchar(1000);
set @T = N'select * from TableName
where left(City,1)in(N''一'',N''二'',N''三'',N''四'',N''五'')';
set @Q = Replace(@T, N'TableName', N'A with (nolock)' );
print @Q;
exec sp_executesql @Q;
确保包含查询文本的变量是nvarchar
。并确保字符串常量以N'
开头