我是編程新手,所以請儘量輕鬆一點。
我正在重寫一個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