|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
我有个带参数的Query 叫qGEHForm22
定义如下:
PARAMETERS [pYear] Long, [pMonth] Text ( 255 );
Select distinct sn,entityid,securityname,isincode,producttype,IIF(ISNULL(ClosingBalance),0,VAL(CLosingBalance)) as CLosingBalance1 , IIF(ISNULL((ImpairmentAllowance)),0,VAL((ImpairmentAllowance))) as Impairement1, IIF(ISNULL((CarryingValue)),0,VAL((CarryingValue))) as CarryingValue1, '22V' as source from Form22_22V where InsuranceIND='Y' And [year]=pYear and [Month]=pMonth
ADO 调用这个query没有问题
Dim aa As ADODB.Command
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Set aa = New ADODB.Command
aa.CommandText = "qGEHForm22"
aa.CommandType = adCmdStoredProc
Set mypar = aa.CreateParameter("pYear", adInteger, 1, 50, 2010)
aa.Parameters.Append mypar
Set mypar = aa.CreateParameter("pMonth", adVarChar, 1, 50, "AUG")
aa.Parameters.Append mypar
Set rs = aa.Execute
Do While Not rs.EOF
Debug.Print rs.Fields(2)
rs.MoveNext
Loop
现在我想用这个带参数的query去insert到新的table
strINSSQL = "Insert into GEHForm22 ([year],[month],entityid,securityname,isincode,producttype,ClosingBalance,Impairement,CarryingValue) "
strFSQL = " select [year],[month],entityid,securityname,isincode,producttype,ClosingBalance1,Impairement1,CarryingValue1 from qGEHFOrm22"
strSQL = strINSSQL + strFSQL
aa.CommandText = strSQL
'cmd.CommandType = adCmdStoredProc
Set mypar = aa.CreateParameter("pYear", adInteger, 1, 50, 2010)
aa.Parameters.Append mypar
Set mypar = cmd.CreateParameter("pMonth", adVarChar, 1, 50, "AUG")
aa.Parameters.Append mypar
aa.Execute
出错Runtime 3709 The connection can't perform such this operation, 大家有什么建议吗,是不是ADO不支持带参数化query的语句
当然我可以再加个Query直接写出Insert,那样的话,我就要创建很多Query,意义就不大了
[ 本帖最后由 kdkboy 于 2010-11-10 12:15 编辑 ] |
|