如何在存储过程中使用函数

时间:2013-07-16 11:33:07

标签: sql-server sql-server-2008 stored-procedures

我有一个函数用于比较两个CSV字符串我想在存储过程中使用此函数 我做了但现在正在工作......我想我正在以错误的方式使用函数 请你修改我的S_P

ALTER PROC [dbo].[bb_AcquireInvtBanksSeekMatch] 
      @acq_targetCountry25 varchar(1500),
      @acq_bizsect25 varchar(1500),
      @acq_stageofCompany varchar(50),
      @acq_invstmntsize25 varchar(1500)  
AS 
    SET NOCOUNT ON 
    SET XACT_ABORT ON  

    BEGIN TRAN


    SELECT [bb_investorbanks_seek].[seek_id], [bb_investorbanks_seek].[user_id],    [bb_investorbanks_seek].[seek_actualRole], 
    [bb_investorbanks_seek].[seek_firmBased5],[bb_investorbanks_seek].    [seek_sectorOperate5],    [bb_investorbanks_seek].[seek_stageCompany], 
    [bb_investorbanks_seek].[seek_lookingToRaise25] 

    FROM   [dbo].[bb_investorbanks_seek] ,[dbo].[bb_user]       


    WHERE 
    (dbo.CompareCSV([bb_investorbanks_seek].[seek_firmBased5] , @acq_targetCountry25)=1 OR 
        dbo.CompareCSV([bb_investorbanks_seek].[seek_sectorOperate5] , @acq_bizsect25)=1 OR
    dbo.CompareCSV([bb_investorbanks_seek].[seek_stageCompany] , @acq_stageofCompany) =1 OR     
    dbo.CompareCSV([bb_investorbanks_seek].[seek_lookingToRaise25] , @acq_invstmntsize25)=1 AND 
([bb_investorbanks_seek].[user_id] = [bb_user].[user_id]) AND ([bb_investorbanks_seek].[user_id] <> 0) 

    COMMIT

2 个答案:

答案 0 :(得分:3)

在SQL Server中调用函数时,它们必须作为SELECT

完成
SELECT [ColumnNameToSelectFromFunction] FROM [Function](Parameters for function all seperated by a ,)

答案 1 :(得分:1)

试试这个 -

ALTER PROC [dbo].[bb_AcquireInvtBanksSeekMatch]

     @acq_targetCountry25 VARCHAR(1500),
     @acq_bizsect25 VARCHAR(1500),
     @acq_stageofCompany VARCHAR(50),
     @acq_invstmntsize25 VARCHAR(1500)

AS BEGIN

     SET NOCOUNT ON
     SET XACT_ABORT ON

     SELECT
           s.[seek_id]
         , s.[user_id]
         , s.[seek_actualRole]
         , s.[seek_firmBased5]
         , s.[seek_sectorOperate5]
         , s.[seek_stageCompany]
         , s.[seek_lookingToRaise25]
     FROM dbo.bb_investorbanks_seek s
     JOIN dbo.bb_user u ON s.[user_id] = u.[user_id]
     WHERE (
                  dbo.CompareCSV(s.[seek_firmBased5] , @acq_targetCountry25) = 1 
               OR dbo.CompareCSV(s.[seek_sectorOperate5] , @acq_bizsect25) = 1 
               OR dbo.CompareCSV(s.[seek_stageCompany] , @acq_stageofCompany) = 1 
               OR dbo.CompareCSV(s.[seek_lookingToRaise25] , @acq_invstmntsize25) = 1 
          )
          AND s.[user_id] <> 0 

END