SQL Server 模板 - 如何转义小于字符?
我喜欢使用 SQL Server 2005 模板来运行常用查询。您可以使用以下语法在模板中包含参数:
<LastName, varchar, 'Bob'>
我有一个查询需要小于或等于运算符<=,但不幸的是,SQL Server 2005 模板将其解释为参数的开头。我一直无法找到使用 < (小于字符)作为文字的方法。
I like to use SQL Server 2005 templates to run frequently used queries. You can include parameters in your templates using this syntax:
<LastName, varchar, 'Bob'>
I have a query that needs the less than or equals to operator <= but unfortunately the SQL Server 2005 template interprets that as the start of a parameter. I have been unable to find a way to use the < (less than character) as a literal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当我指定模板参数的值时,这对我来说运行良好:
也许您没有每个参数的“<”和“>”正确配对
编辑我现在看到问题:
结果是:
尝试制作“<”字符到参数中,如下所示:
它的结果是:
或分割行,换行符似乎有所不同:
结果是:
when I Specify Values for Template Parameters, this runs fine for me:
perhaps you do not have every parameter's "<" and ">" paired properly
EDIT I see the problem now:
results in:
try making the "<" character into a parameter, like this:
it results in:
OR split the lines, line breaks seem to make a difference:
results in:
使用模板
如果选择(菜单)查询>指定模板参数的值,替换的默认值是“xtype <= 60”,这是正确的,并且替换后,生成的查询文本正是
人们所期望的。换句话说,“<”似乎并非如此。符号需要转义。然而,“>”更有问题的是:
打开“指定值”对话框时这会失败。但是,在这种情况下,可以指定
并输入
“值”字段以进行替换。这
又产生了人们所期望的结果。所以看来替换的默认值可能不包含“>”。
With template
If you select (menu) Query > Specify Values for template parameters, the default value for replacement is "xtype <= 60", which is correct, and upon substitution, the resulting query text is
which is exactly what one would expect. In other words, it does not appear to be the case that the "<" symbol needs to be escaped. However, ">" is more problematic:
This will fail when opening the "specify values" dialog. However, in this instance, it is fine to specify
and enter
in the "value" field for replacement. This produces
which is again as one would expect. So it would seem that the default value for replacement may not contain a ">".