我有SQL Rule,它检查以数字开头的字符串。我有一些非英文数字,并且包含一个条件。
当我将sql squery存储为字符串显示在行中时?代替字母
列数据类型为nvarchar,排序规则为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'???????')
答案 0 :(得分:0)
我怀疑这是一个动态查询。也许您的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'