选择具有Split功能的语句

时间:2013-10-22 07:59:23

标签: sql sql-server stored-procedures

我在存储过程中使用select split函数来传递多选IDS,如下所示。

SELECT     Status AS ClientInbox, COUNT(submitTime) AS CountStatus
        FROM         dbo.ClientInbox with (nolock) join debtor with (nolock) on ClientInbox.debtorid = debtor.id
        WHERE      (submitTime >= @fromDate and submittime <= @toDate)
         and debtor.clientid IN  (SELECT ID FROM [dbo].[split_IDs] (@clientid,','))
        GROUP BY Status 

其中[dbo]。[split_IDs]是一个函数。我的问题是在测试时,当我用一组诸如('1,2,3,4,5')之类的字符串重写变量@clientid时,查询返回所需的记录。但是,当我从VS运行该过程时,它不会返回确切的记录。我试着通过执行SQL Server中的过程来找出问题所在,如下所示

USE [Volare_2005]
GO

DECLARE @return_value int
DECLARE @fromDate datetime
DECLARE @toDate datetime

EXEC    @return_value = [dbo].[GetSMSReportDate]
        @fromDate = '2000-04-06T12:23:45',
        @toDate =  '2013-10-22T21:10:12',
        @option = 0 ,
        @collectorid = 0,
        @supervisorid = 0,
        @clientid = N'95,1'

--SELECT    'Return Value' = @return_value

GO

它也无法返回记录。但是,当我通过在过程中重新定义变量@clientid来运行查询时,它工作正常。我不确定我是不是错了。请任何帮助将不胜感激

0 个答案:

没有答案