我想使用一个存储过程,它可以使一些参数为空值,然后测试它是否参数为空并进行一些编码:我只想知道这个存储过程是否有问题
这是存储过程
create proc rechercherGIACetAffiche @nomgiac varchar(20),@nom varchar(30) = null,@par varchar(50) = null
as
begin
IF @nom is null and @par is null
begin
select [ID_Dossier] as 'ID_Dossier'
,[ID_Entreprise] as 'ID_Entreprise'
,[Date_Depot] as 'Date_Dépôt'
,[Type_Etude] as 'Type_Etude'
,[Dernier_Type] as 'Dernier_Type'
,[Eligibile] as 'Eligibilité'
,[Fiche_Information] as 'Fiche_Information'
,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
,[Fiche_Renseignment] as 'Fiche_Renseignment'
,[Attestation] as 'Attestation'
,[Date_Debut] as 'Date_Début'
,[Date_Fin] as 'Date_Fin'
,[ID_Cabinet] as 'ID_Cabinet'
,[Montant_Demander] as 'Montant_Demander'
,[Duree] as 'Durée'
,[Porcentage_Taux] as 'Pourcentage,Taux' from Dossier where Nom_Giac = @nomgiac
return
end
if @par is not null and @nom='CNSS'
begin
select d.[ID_Dossier] as 'ID_Dossier'
,d.[ID_Entreprise] as 'ID_Entreprise'
,[Date_Depot] as 'Date_Dépôt'
,[Type_Etude] as 'Type_Etude'
,[Dernier_Type] as 'Dernier_Type'
,[Eligibile] as 'Eligibilité'
,[Fiche_Information] as 'Fiche_Information'
,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
,[Fiche_Renseignment] as 'Fiche_Renseignment'
,[Attestation] as 'Attestation'
,[Date_Debut] as 'Date_Début'
,[Date_Fin] as 'Date_Fin'
,[ID_Cabinet] as 'ID_Cabinet'
,[Montant_Demander] as 'Montant_Demander'
,[Duree] as 'Durée'
,[Porcentage_Taux] as 'Pourcentage,Taux'
from dbo.Dossier d inner join entreprise e on d.ID_Entreprise=e.ID_Entreprise
where CNSS_Entreprise=@par and d.Nom_Giac=@nomgiac
return
end
else if @par is not null and @nom='RS'
begin
select [ID_Dossier] as 'ID_Dossier'
,[ID_Entreprise] as 'ID_Entreprise'
,[Date_Depot] as 'Date_Dépôt'
,[Type_Etude] as 'Type_Etude'
,[Dernier_Type] as 'Dernier_Type'
,[Eligibile] as 'Eligibilité'
,[Fiche_Information] as 'Fiche_Information'
,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
,[Fiche_Renseignment] as 'Fiche_Renseignment'
,[Attestation] as 'Attestation'
,[Date_Debut] as 'Date_Début'
,[Date_Fin] as 'Date_Fin'
,[ID_Cabinet] as 'ID_Cabinet'
,[Montant_Demander] as 'Montant_Demander'
,[Duree] as 'Durée'
,[Porcentage_Taux] as 'Pourcentage,Taux'
from dbo.Dossier
where Nom_Giac=@nomgiac and ID_Entreprise in( select ID_Entreprise
from dbo.Entreprise
where Raison_Social=@par)
return
end
else if @par is not null and @nom ='Date'
begin
declare @v smalldatetime,@b smalldatetime
set @b=SUBSTRING(@par,1,4)
set @v=SUBSTRING(@par,5,8)
select [ID_Dossier] as 'ID_Dossier'
,[ID_Entreprise] as 'ID_Entreprise'
,[Date_Depot] as 'Date_Dépôt'
,[Type_Etude] as 'Type_Etude'
,[Dernier_Type] as 'Dernier_Type'
,[Eligibile] as 'Eligibilité'
,[Fiche_Information] as 'Fiche_Information'
,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
,[Fiche_Renseignment] as 'Fiche_Renseignment'
,[Attestation] as 'Attestation'
,[Date_Debut] as 'Date_Début'
,[Date_Fin] as 'Date_Fin'
,[ID_Cabinet] as 'ID_Cabinet'
,[Montant_Demander] as 'Montant_Demander'
,[Duree] as 'Durée'
,[Porcentage_Taux] as 'Pourcentage,Taux'
from Dossier
where Date_Depot between @b and @v and Nom_Giac like @nomgiac
return
end
end