Sql de nullsa getir değilse getirme

kullanici402302 (1) 6 yıl önce sordu
Declare @projeId Nvarchar(50)

Set @projeId = ''

Select *
 From  dbo.Actions where ProjectId = @projeId  

eğer null sa projeId bütün değerleri getir değilse sadece 1 tane kendisinin olan projeId sini getir nasıl yapabilirim??

Toplam 1 cevap


alattin (16999) 6 yıl önce cevapladı

En basitinden şu şekilde yazabilirsin:

declare @projeId nvarchar(50);

if (@projeId is NULL)
BEGIN
select * from dbo.Actions
END
else
BEGIN
select * from dbo.Actions Where ProjeId=@projeId
END

Fakat '' #null anlamına gelmez. Bunu unutma, eğer gerçekten #null değerleri koşula sokmak istiyorsan yukarıdaki gibi kodu kullanmalısın.