
/***************************************
* STORED stp_selDestListePrelByConditio
*
* Ottiene i destinatari delle liste di prelievo data la condizione indicata
*
* Steamware, S.E.L.
* mod: 2010.11.02
*
****************************************/
CREATE PROCEDURE stp_selDestListePrelByConditio
(
	@conditio NVARCHAR(20)
)
AS

IF (@conditio='01-PreFus')
BEGIN
	SELECT        CAST('*' AS NVARCHAR(6)) AS value, CAST('*' AS NVARCHAR(50)) AS label, '01-PreFus' AS conditio
END

ELSE IF (@conditio='01-PreAnim')
BEGIN
	SELECT        CAST(CodCliente AS NVARCHAR(6)) AS value, CAST(CodCliente AS NVARCHAR(6)) +'- ' +CAST(RagSociale AS NVARCHAR(50)) AS label, '01-PreAnim' AS conditio
	FROM            RilPro.AnagClienti
	ORDER BY label
END

ELSE IF (@conditio='02-PreCli') 
BEGIN
	SELECT        CAST(CodCliente AS NVARCHAR(6)) AS value, CAST(CodCliente AS NVARCHAR(6)) +'- ' +CAST(RagSociale AS NVARCHAR(50)) AS label, '02-PreCli' AS conditio
	FROM            RilPro.AnagClienti
	ORDER BY label
END

ELSE IF (@conditio='04-Odette') 
BEGIN
	SELECT        CAST(CodCliente AS NVARCHAR(6)) AS value, CAST(CodCliente AS NVARCHAR(6)) +'- ' +CAST(RagSociale AS NVARCHAR(50)) AS label, '04-Odette' AS conditio
	FROM            RilPro.AnagClienti
	ORDER BY label
END

ELSE IF (@conditio='05-TerAn') 
BEGIN
	SELECT        CAST(CodTerzista AS NVARCHAR(6)) AS value, CAST(CodTerzista AS NVARCHAR(6))+ '- '+CAST(DescTerzista AS NVARCHAR(50)) AS label, '05-TerAn' AS conditio
	FROM            RilPro.AnagDepositi
	ORDER BY label
END

ELSE IF (@conditio='03-TerWip') 
BEGIN
	SELECT        CAST(CodTerzista AS NVARCHAR(6)) AS value, CAST(CodTerzista AS NVARCHAR(6))+ '- '+CAST(DescTerzista AS NVARCHAR(50)) AS label, '03-TerWip' AS conditio
	FROM            RilPro.AnagDepositi
	ORDER BY label
END

ELSE   -- Se non configurata prendo elenco destinatari esterni
BEGIN
	SELECT       '-99999' AS value, 'STORED [stp_selDestListePrelByConditio] da configurare!!!' AS label, '999-ND' AS conditio
	FROM            RilPro.AnagDepositi
	ORDER BY label
END

RETURN
