我是编程新手,所以请尽量轻松一点。
我正在重写一个Visual Basic到SQL。将VB脚本转换为SQL(VB将2个插入到一列中)
VB代码将文件转换后的数据插入tableY
。
我想要我的SQL代码将数据加载到tableX
,将其转换并加载到tableY
。
我创建了tableX
并从文件中插入未转换的数据。现在我想转换它,并在发现问题时将其插入tableY
。
这里是VB代码
IF some-if-statement THEN
DTSDestination("max") = Mid(DTSSource("Col001"),985,5)
another MID
another MID
another MID
DTSDestination("max") = Mid(DTSSource("Col001"),983,5)
这里是我的SQL版本:
INSERT INTO tableY (max, aaa, bbb, ccc, max)
select
substring(Col001,985,5),
another substring,
another substring,
another substring,
substring(Col001,983,5)
from tableX
where some-where-statement
的问题是,我想插入2个值[substring(Col001,985,5)
和substring(Col001,983,5)]
成1列。
显然SQL给我一个错误:
The column name 'max' is specified more than once in the SET clause or column list of an INSERT. A column cannot be assigned more than one value in the same clause. Modify the clause to make sure that a column is updated only once. If this statement updates or inserts columns into a view, column aliasing can conceal the duplication in your code.`
我敢肯定的是,VB版本的作品,尽管它不应该 - 因为它做同样的事情。
关于如何解决此问题的任何想法?只插入一个值不适用于我,因为我不知道哪一个是正确的。
看来你只是覆盖VB版本中的Max字段。你想在Max中存储连接值吗?你能举一个例子说明字段值应该是什么样子? – Coolshaikh
在select case和if语句之间,你应该能够委托哪些值需要作为插入语句的一部分。 –
你能提供'tableY'的表结构吗?通过你的SQL,你有2列名为'max'。或者@Coolshaikh说,你想存储连接值? – Prisoner