我收到 SELECT Scope_Identity() 错误
我正在从表单中插入一行新数据。该行生成一个自动增强的 ID(RBID)。
我试图立即抓住它并将它(RBID)插入另一行,以便在需要时可以引用它。
<cfquery name="recbilling" datasource="#request.dsn#" result="myResult">
INSERT INTO RBilling
(CID, UserID, DateCompleted, ClientID, Title, Qty, Rate, Taxable, Description, NextBillingDate,
FrequencyUnit, FrequencyDuration, ProjectID)
VALUES (
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#CID#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#UserID#">,
<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#DateCompleted#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ClientID#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#text0#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#Qty#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#text2#">,
<cfqueryparam cfsqltype="CF_SQL_BIT" value="#Taxable#">,
<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#text1#">,
<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#NextBillingDate#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FrequencyUnit#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FrequencyDuration#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ProjectID#">)
</cfquery>
<cfquery name="getRBID" datasource="#request.dsn#">
SELECT Scope_Identity() as newID
</cfquery>
<cfset RBID = #getRBID.newID#>
</cfif>
<cfquery name="submithourssubmit" datasource="#request.dsn#">
INSERT INTO Billedfees
(CID, UserID, DateCompleted, ClientID, Title, Qty, Rate, Taxable, Description, ProjectID, RBID)
VALUES (
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#CID#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#UserID#">,
<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#DateCompleted#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ClientID#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#text0#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#Qty#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#text2#">,
<cfqueryparam cfsqltype="CF_SQL_BIT" value="#Taxable#">,
<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#text1#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ProjectID#">
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#RBID#">
)
</cfquery>
我得到的错误是:执行数据库查询时出错。[Macromedia][SQLServer JDBC 驱动程序][SQLServer]'@P11' 附近的语法不正确。
错误发生在第 57 行。
我花了一段时间才弄清楚@P11 是什么,但似乎第一个查询中的 FrequencyUnit 或第二个插入查询中的 RBID 都有问题。
数据类型设置正确。
先感谢您。
编辑:
SQL 字符串 (param 1) = [type='IN', class='java.lang.Integer', value='15488', sqltype='CF_SQL_INTEGER'] , (param 2) = [type='IN', class ='java.lang.Integer', value='21066', sqltype='CF_SQL_INTEGER'] , (param 3) = [type='IN', class='java.sql.Timestamp', value='2013-03 -22 00:00:00.0', sqltype='CF_SQL_TIMESTAMP'] , (param 4) = [type='IN', class='java.lang.Integer', value='143933', sqltype='CF_SQL_INTEGER'] , (param 5) = [type='IN', class='java.lang.String', value='Software Test 3', sqltype='CF_SQL_VARCHAR'] , (param 6) = [type='IN', class='java.lang.Float', value='1.0', sqltype='CF_SQL_REAL'] , (param 7) = [type='IN', class='java.lang.Float',value='33.0', sqltype='CF_SQL_REAL'] , (param 8) = [type='IN', class='java.lang.Boolean', value='false', sqltype='CF_SQL_BIT'] , (param 9) = [type='IN', class='java.lang.String', value='Software Test 3', sqltype='CF_SQL_LONGVARCHAR'] , (param 10) = [type='IN', class=' java.lang.Integer', value='0', sqltype='CF_SQL_INTEGER'] , (param 11) = [type='IN', class='java.lang.Integer', value='153314', sqltype= 'CF_SQL_INTEGER']CF_SQL_LONGVARCHAR'] , (param 10) = [type='IN', class='java.lang.Integer', value='0', sqltype='CF_SQL_INTEGER'] , (param 11) = [type='IN' , 类='java.lang.Integer', 值='153314', sqltype='CF_SQL_INTEGER']CF_SQL_LONGVARCHAR'] , (param 10) = [type='IN', class='java.lang.Integer', value='0', sqltype='CF_SQL_INTEGER'] , (param 11) = [type='IN' , 类='java.lang.Integer', 值='153314', sqltype='CF_SQL_INTEGER']
这是我到目前为止得到的:
<cftransaction>
<cfset NextBillingDate = #DateAdd("#FrequencyUnit#", "#FrequencyDuration#", #DateCompleted#)#>
<cfquery name="recbilling" datasource="#request.dsn#" result="myResult">
INSERT INTO RBilling
(CID, UserID, DateCompleted, ClientID, Title, Qty, Rate, Taxable, Description, NextBillingDate,
FrequencyUnit, FrequencyDuration, ProjectID)
VALUES (
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#CID#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#UserID#">,
<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#DateCompleted#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ClientID#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#text0#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#Qty#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#text2#">,
<cfqueryparam cfsqltype="CF_SQL_BIT" value="#Taxable#">,
<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#text1#">,
<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#NextBillingDate#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FrequencyUnit#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#FrequencyDuration#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ProjectID#">)
</cfquery>
<cfoutput>
<Cfset RBID="#myResult.identitycol#">
</cfoutput>
<cfquery name="submithourssubmit" datasource="#request.dsn#">
INSERT INTO Billedfees
(CID, UserID, DateCompleted, ClientID, Title, Qty, Rate, Taxable, Description, ProjectID, RBID)
VALUES (
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#CID#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#UserID#">,
<cfqueryparam cfsqltype="CF_SQL_TIMESTAMP" value="#DateCompleted#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ClientID#">,
<cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#text0#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#Qty#">,
<cfqueryparam cfsqltype="CF_SQL_REAL" value="#text2#">,
<cfqueryparam cfsqltype="CF_SQL_BIT" value="#Taxable#">,
<cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#text1#">,
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#ProjectID#">
<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#RBID#">
)
</cfquery>
这给了我同样的错误:执行数据库查询时出错。[Macromedia][SQLServer JDBC 驱动程序][SQLServer]'@P11' 附近的语法不正确。
错误发生在第 59 行。
第 59 行是第二个插入查询中的第 59 行。
如果您需要其他任何东西,请告诉我。
谢谢