0

我有一个这样的存储过程:

  ALTER PROCEDURE [dbo].[T_TransactionSummary]  
                        @startDate datetime,  
                        @endDate datetime,
                       -- @locations integer
                       @locations dbo.Loc readonly

AS
BEGIN
    DECLARE @fromDate datetime = convert(varchar(10), @startDate, 121) + ' 00:00:00.000';
DECLARE @toDate datetime = convert(varchar(10), @endDate, 121) + ' 11:59:59.999';

SELECT     COUNT(*) AS CarCount, Location_tbl.LocName
, REPLACE(CONVERT(varchar(11), Transaction_tbl.dtime, 113), ' ', '-') AS Date_time
, CASE Transaction_tbl.Compl WHEN 'True' THEN 'Complementary' 
WHEN 'False' THEN 'Non-Complementary' ELSE 'Other' END AS Expr1
, VType_tbl.Vtype, CASE WHEN (VType_tbl.Vtype = 'Normal' AND Transaction_tbl.Compl = 'False') THEN COUNT(*) 
                      * 50 WHEN (VType_tbl.Vtype = 'VIP' AND Transaction_tbl.Compl = 'False') THEN COUNT(*) * 100 ELSE 0 END AS Total, 
                      CASE WHEN Transaction_tbl.Paid = 'False' THEN 0 ELSE SUM(Transaction_tbl.PAmount) END AS CIH
FROM         Transaction_tbl INNER JOIN
                      Location_tbl ON Transaction_tbl.Locid = Location_tbl.Locid LEFT OUTER JOIN
                      VType_tbl ON Transaction_tbl.vtid = VType_tbl.vtid LEFT OUTER JOIN
                      Make_tbl ON Transaction_tbl.mkid = Make_tbl.mkid LEFT OUTER JOIN
                      Color_tbl ON Transaction_tbl.Colid = Color_tbl.colid LEFT OUTER JOIN
                      PlateSource_tbl ON Transaction_tbl.PSID = PlateSource_tbl.PSID
WHERE     (Transaction_tbl.dtime BETWEEN @fromDate AND @toDate) 
--AND (Location_tbl.Locid IN (@locations))
AND (Location_tbl.Locid IN (select Lo from @locations))
GROUP BY Location_tbl.LocName, REPLACE(CONVERT(varchar(11), Transaction_tbl.dtime, 113), ' ', '-')
, VType_tbl.Vtype, Transaction_tbl.Compl, Transaction_tbl.Paid
ORDER BY Location_tbl.LocName, Date_time DESC, VType_tbl.Vtype, Transaction_tbl.Compl

END

我的 locid 列是整数,这个 locid 来自我的列表框。如果我选择一项,就会出现 1 个 locid。如果我选择 2 item 2 locid will come.. 我有一个 ListBox 填充 @locations 参数(一个整数),我把我的列表框值像这样

cnt = LSTlocations.SelectedItems.Count
  Dim dtlist As New DataTable()
    Dim locid As Integer
    If cnt > 0 Then
        For i = 0 To cnt - 1
            dtlist.Columns.Add(locid, GetType(Integer))
            Dim locationanme As String = LSTlocations.SelectedItems(i).ToString
            locid = RecordID("Locid", "Location_tbl", "LocName", locationanme)
            dtlist.Rows.Add(locid)
        Next
End If
 Dim da As New SqlDataAdapter
        Dim ds As New DataSet
        Dim cmd23 As New SqlCommand("T_TransactionSummary", con.connect)
        cmd23.CommandType = CommandType.StoredProcedure
        Dim tvp1 As SqlParameter = cmd23.Parameters.AddWithValue("@locations", dtlist)
         tvp1.SqlDbType = SqlDbType.Structured
         tvp1.TypeName = "dbo.Loc"
        da.SelectCommand = cmd23
        da.Fill(ds) 

但我收到这样的错误:

操作数类型冲突:表类型与 int 不兼容

我知道错误来自“ AND (Location_tbl.Locid IN (select Lo from @locations))”我正在尝试将多个参数传递给@locations,..这就是我收到错误的原因..如果有人知道该怎么做。请帮助我找出..

4

0 回答 0