VBScript SQL选择查询澄清和变量替换 [英] VBScript SQL select query clarification and variable substitution

查看:82
本文介绍了VBScript SQL选择查询澄清和变量替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已多次阅读此条目(http://stackoverflow.com/questions/8513185/vbscript-to-correctly-re-format-a-delimited-text-file),但仍然不了解.Execute节。

I have read this entry (http://stackoverflow.com/questions/8513185/vbscript-to-correctly-re-format-a-delimited-text-file) many times and still do not understand the .Execute section.

WScript.Echo oTDb.Execute(Replace("SELECT * FROM [@T]", "@T", sTbl1)) _
.GetString( adClipString, , "|", vbCrLf, "" )

我遇到麻烦的部分是[@T]和 @T。

The pieces I am having trouble with are the [@T] and "@T".

我知道正是 @T正在读取文件名模式文件和[@T]必须使用 @T作为替代。我找不到的地方是提到/说过的地方。

I know it is the "@T" that is reading the filename in the schema file and and the [@T] must be using the "@T" as a substitute. What I cannot find out is where this is mentioned/spoken about.

我还有一些其他问题:
1.如果文件名可以用a代替变量,那还能做什么?
2.变量维护的规则是什么
它们必须以@符号开头
是否有保留字
如果必须以@符号开头,是否下一个字符必须是字母

Some addition questions I have are: 1. If the filename can be substituted with a variable then what else can? 2. What are the rules for maintaining variables Do they have to start with the @ symbol Are there any reserved words If they have to start with the @ symbol, does the next character have to be a letter

推荐答案

我对@Milton的担忧/困惑负责:

As I am responsible for @Milton's worry/puzzlement:

在VBScript中没有变量插值/替换。其他语言-例如Perl-当您用特殊符号标记替换项时,会将变量甚至表达式结果拼接成字符串文字。在VBScript中没有这样有趣的字母。

There is no variable interpolation/substitution in VBScript. Other languages - e.g. Perl - will splice variables or even expression results into string literals when you mark the replacements with special symbols. No such funny letters in VBScript.

SQL方言允许使用参数化命令替换要替换的部分?和/或以@等符号开头的名称。但是在这里ADO从未看到@T-VBScript的Replace()函数已经将表名插入之前,结果字符串被发送到.Execute()。

SQL dialects allow parameterized commands in which parts to be replaced are marked by ? and/or names prefixed by symbols like @. But here ADO never sees the @T - VBScript's Replace() function has interpolated the table name before the resulting strings is send to .Execute().

通过串联从各个部分(SQL语句,.Run或.Exec的命令行,...)构建复杂的字符串很麻烦。最重要的缺点是您无法(证明)所有和&字符串。

Building complex strings from parts (SQL statements, commandlines for .Run or .Exec, ...) by concatenation is cumbersome. The most important drawback is that you can't (proof) read the string anymore for all those " and &.

一个简单的解决方法是使用Replace(),如

A simple workaround is to use Replace(), as in

[sResult = ] Replace("SELECT * FROM [@T]", "@T", sTbl1)

我使用@只是为了让占位符脱颖而出,因为您必须堆叠/嵌套替换 ()在模板上需要更多替换时调用,其他策略也值得考虑:

I used the @ just for letting the placeholder stand out. As you would have to stack/nest the Replace() calls when you need more substitutions on the template, other strategies are worth considering:


  1. 编写使用模板字符串和替换字典,将Regexp.Replace()应用于字符串

  2. 使用.NET的System.Text.StringBuilder及其.AppendFormat进行像sprintf样式的切片

这篇关于VBScript SQL选择查询澄清和变量替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆