我是 StackOverflow 的新手,我在这里提出了一个我似乎无法找到答案的问题。
我正在尝试执行一个存储过程,该过程提取数据以使用 BCP 将它们分成不同的文件。
这是我的存储过程:
CREATE PROCEDURE [dbo].[GetAllDeaths]
@Datname varchar(2)
AS
SET NOCOUNT ON
DECLARE @getid CURSOR
DECLARE @getMax CURSOR
DECLARE @LevelID int
DECLARE @SubLevelID int
DECLARE @getNumber int
DECLARE @SQL varchar(1000)
DECLARE @Cmd varchar(1000)
DECLARE @OutputFile varchar(1000)
DECLARE @ServerName varchar(100)
DECLARE @LevelName varchar(1)
set @getid= CURSOR FOR
SELECT LevelID, SubLevelID from [crashtrack3].[dbo].LevelTableAux
open @getid
FETCH NEXT
FROM @getid into @LevelID, @SubLevelID
WHILE (@@FETCH_STATUS =0)
BEGIN
SET @getMax = CURSOR FOR
Select sum(Number)
from [crashtrack3].[dbo].[tmpDeath]
where LevelID = @LevelID and OptionalSubLevelID = @SubLevelID
IF @LevelID =1
BEGIN
SET @LevelName='J'
END
ELSE IF @LevelID =2
BEGIN
SET @LevelName='A'
END
ELSE IF @LevelID =3
BEGIN
SET @LevelName='E'
END
ELSE IF @LevelID=4
BEGIN
SET @LevelName='I'
END
OPEN @getMax
FETCH NEXT
FROM @getMax into @getNumber
BEGIN
SET @ServerName = '*********\SQLEXPRESS'
SET @SQL = '"Select LowResMapX, LowResMapY, ceiling(2000*(Number/'+CONVERT(varchar,@getNumber)+'.0)) as Cantidad from [crashtrack3].[dbo].[tmpDeath] where LevelID = '+CONVERT(char(1),@LevelID)+' and OptionalSubLevelID = '+CONVERT(char(1),@SubLevelID)+' order by LowResMapX asc"'
SET @OutputFile = 'C:\MyData\'+@LevelName+'0'+CONVERT(char(1),@SubLevelID)+'_("name_of_the_file_HERE").dat'
print @OutputFile
print 'Level ' + cast(@LevelID as char)
print 'Sub Level ' + cast(@SubLevelID as char)
SET @Cmd = 'bcp '+@SQL+' queryout '+ @OutputFile + ' -c -S '+@ServerName+' -T'
print @Cmd
EXEC master..xp_cmdshell @Cmd
FETCH NEXT
FROM @getMax into @getNumber
END
CLOSE @getMax
DEALLOCATE @getMax
FETCH NEXT
FROM @getid INTO @LevelID, @SubLevelID
END
DELETE [crashtrack3].[dbo].[tmpDeath]
CLOSE @getid
DEALLOCATE @getid
这是我的 VBScript 文件:
DIM Datname
DIM EnemyWeaponID
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "SQLOLEDB"
objConnection.Open "Server=******\SQLEXPRESS;Database=crashtrack3;Integrated Security=SSPI"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
EnemyWeaponID=1
objCommand.CommandText = "INSERT INTO [crashtrack3].[dbo].[tmpDeath] ([LevelID], [OptionalSubLevelID], [LowResMapX], [LowResMapY], [Number]) select LevelID, OptionalSubLevelID, LowResMapX, LowResMapY, count(LowResMapY) from [crashtrack3].[dbo].[PlayerDiedorFailed] where EnemyWeaponID=+"EnemyWeaponID"+ Group by LevelID, OptionalSubLevelID, LowResMapX,LowResMapY order by LowResMapX asc"
WScript.Echo objCommand.CommandText
Set objRecordSet = objCommand.Execute
IF EnemyWeaponID = 1 THEN
Datname="DE"
ELSE IF EnemyWeaponID = 2 THEN
Datname="RS"
ELSE IF EnemyWeaponID = 3 THEN
Datname="RW"
END IF
END IF
END IF
objCommand.CommandText = "EXEC GetAllDeaths '"+Datname+"'"
Set objRecordSet = objCommand.Execute
objRecordset.close
objConnection.Close
set objConnection = Nothing
WScript.Echo "Success!"
我真正需要的是知道如何使 vbs 文件上的“Datname”包含在存储过程的执行中。
PD:对不起我的英语,如果我没有意义,但我现在被困了一个星期。