如何选择将多个id作为varchar列表传递给SQL Server?

时间:2017-11-27 19:09:17

标签: sql-server

我有这个存储过程

CREATE PROCEDURE Research
    (@ExamenId INT = NULL)
AS  
BEGIN  
    CREATE TABLE #EXAMENS (PRESC_ID int, DEMANDE_ID int, EXAMEN_ID int)  

    IF (@ExamenId IS NOT NULL)   
    BEGIN  
        INSERT INTO #EXAMENS (PRESC_ID, DEMANDE_ID, EXAMEN_ID)
            SELECT 
                OPI.PRESC_ID, PRPED.DEMANDE_ID, PRPE.EXAMEN_ID  
            FROM 
                PG_RADIO_PRESC_EXAMEN PRPE WITH (NOLOCK)  
            INNER JOIN 
                OPIUM_PRESC_ITEM OPI WITH (NOLOCK) ON OPI.ITEM_ID = PRPE.ITEM_ID  
            LEFT JOIN  
                PG_RADIO_PRESC_EXD_DEM PRPED WITH (NOLOCK) ON PRPED.EXAMEN_ID = PRPE.EXAMEN_ID  
            WHERE 
                PRPE.EXAMEN_ID = @ExamenId  
    END  

    SELECT
        tes.EXAMEN_ID, tes.PARAMETRE_ID,
        TXT_CODE_ID, VALEUR
    FROM
        (SELECT 
             PRPE.EXAMEN_ID, PRPEG.ParametreEntreeId AS PARAMETRE_ID,
             0 AS TXT_CODE_ID,
             ISNULL(Replace(CAST(pfs.FORM_SOURCE_SAISIE AS VARCHAR(MAX)), '', ''), Replace(CAST(pf.FORM_SOURCE AS VARCHAR(MAX)), '', '')) AS VALEUR
         FROM 
             #EXAMENS tmpexam WITH (NOLOCK)  
         INNER JOIN 
             PG_RADIO_PRESC_EXAMEN PRPE WITH (NOLOCK) ON PRPE.EXAMEN_ID = tmpexam.EXAMEN_ID  
         INNER JOIN 
             PG_RADIO_PARAMETRE_ENTREE_GESTE PRPEG ON PRPEG.GesteId = PRPE.GESTE_ID  
         INNER JOIN
             PG_PARAM_ENTREE_FORMULAIRE pf ON pf.PARAMETRE_ID = PRPEG.ParametreEntreeId  
         LEFT JOIN
             PG_PARAM_ENTREE_FORMULAIRE_SAISI pfs ON pfs.EXAMEN_ID = tmpexam.EXAMEN_ID   
                                                  AND pfs.PARAMETRE_ID = PRPEG.ParametreEntreeId) AS tes
    LEFT JOIN
        PG_PARAM_ENTREE_PARAMETRE ps ON ps.PARAMETRE_ID = tes.PARAMETRE_ID 
    ORDER BY 
        ps.RANG ASC
END 

为一次考试返回EXAMEN_ID,PARAMETRE_ID,TXT_CODE_ID,VALEUR。

现在我想传递一个id列表varchar,并为每个id返回其信息EXAMEN_ID,PARAMETRE_ID,TXT_CODE_ID,VALEUR。

谢谢

0 个答案:

没有答案