我在 sql server 2008 R2 MSSQL 程序中有以下程序
/****** Object: UserDefinedFunction [dbo].[test_fn_transaction_search] Script Date: 01/30/2015 11:57:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROCEDURE test_fn_transaction_insert_log @receipt varchar(25), @amount varchar(25), @stdt varchar(25),
@enddt varchar(25)
AS
SET NOCOUNT ON
INSERT INTO [TransactionLog] ( TimeStamp, CashierID, Total,RecurringStartDate,
RecurringStopDate, CustomerID, ReceiptNumber, Voided, Attendee, ItemLookupCode)
SELECT CURRENT_TIMESTAMP AS [TimeStamp], tr.CashierID, @amount, @stdt,@enddt,c.ID,tr.ReceiptNumber,
tr.Voided,it.ItemLookupCode, tr.Comment
from "Transaction" tr, TransactionEntry trent, Item it, Customer c
where trent.TransactionID = tr.ID
and trent.ItemID = it.ID
and c.ID=tr.CustomerID
and tr.ReceiptNumber=@receipt
GO
我在Java中使用它如下
Java 道方法
public String saveTr(String a, String b, String c, String d) {
try
{
SqlServerConn conn = new SqlServerConn();
connect=conn.getConnection();
String SQL = String.format("Exec test_fn_transaction_selected ?,?,?,?");
pstmt = connect.prepareStatement(SQL);
pstmt.setString(1, a);
pstmt.setString(2, b);
pstmt.setString(3, c);
pstmt.setString(4, d);
rs = pstmt.executeQuery();
}
catch (Exception e2)
{
e2.printStackTrace();
return "fail";
}
//ArrayList<Transactions> list=getrowFromResultSet2(rs);
return "success";
}
我得到以下异常。谁能告诉我出了什么问题。
我在网上阅读了以下有关 MSSQL 的内容,这引起了很多混乱。
a) 函数不能用于将值插入到临时表以外的表中。b) 程序不能返回表值。
那么如何才能做到以下三个 a)向函数/proc 发送 3 个参数 b)使用输入参数作为 select 语句的输入,c)将返回的值插入到表中,d)返回插入的行/成功/失败状态。
截至目前,我得到以下异常
com.microsoft.sqlserver.jdbc.SQLServerException: The request for procedure 'test_fn_transaction_selected' failed because 'test_fn_transaction_selected' is a table valued function object.