MS-SQL任何人可以幫我寫了下面的MS-SQL SP到MySQL SP,存儲過程到MySQL
使用這樣的:
CREATE PROCEDURE sp_InputWork
@_DelimitedString nvarchar(MAX)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @_DataRow nvarchar(MAX)
DECLARE @_DescriptionOfWorkDone nvarchar(MAX)
DECLARE @_TemporaryStorage nvarchar(MAX)
DECLARE @_QTY int
DECLARE @_Total int
DECLARE @_CurrentField int
WHILE CHARINDEX(';', @_DelimitedString) > 0
BEGIN
SET @_DataRow = CAST(SUBSTRING(@_DelimitedString, 0, CHARINDEX(';', @_DelimitedString)) AS nvarchar(MAX))
SET @_CurrentField = 1
WHILE CHARINDEX(',', @_DataRow) > 0
BEGIN
SET @_TemporaryStorage = CAST(SUBSTRING(@_DataRow, 0, CHARINDEX(',', @_DataRow)) AS nvarchar(MAX))
IF @_CurrentField = 1
SET @_QTY = CAST(@_TemporaryStorage AS int)
IF @_CurrentField = 2
SET @_DescriptionOfWorkDone = @_TemporaryStorage
IF @_CurrentField = 3
SET @_Total = CAST(@_TemporaryStorage AS int)
SET @_DataRow = SUBSTRING(@_DataRow, CHARINDEX(',', @_DataRow) + 1, LEN(@_DataRow))
SET @_CurrentField = @_CurrentField + 1
END
INSERT INTO tblWorkDone (QTY, DescriptionOfWorkDone, Total) VALUES (@_QTY, @_DescriptionOfWorkDone, @_Total)
SET @_DelimitedString = SUBSTRING(@_DelimitedString, CHARINDEX(';', @_DelimitedString) + 1, LEN(@_DelimitedString))
END
END
你得到什麼錯誤,你有什麼嘗試? –
@RaviSingh我正在做的是將一個字符串傳遞給SP(a,test,100.00,1; b,test1,150.00,c;),即由昏迷分隔的值和由分號分隔的值設置,我想將SP循環通過值集,然後通過字段然後插入到表中。我沒有在Mysql中試過這個。我從一個網站獲得這個sp [link] http://www.vbforums.com/showthread.php?516496-Inserting-datagrid-view-data-to-sql-database [/ link] –
這應該在mysql中工作更改:1)將'charindex'更改爲'instr()'。 2)使用「IF..THEN」而不是「IF」。 –