webForumDet fria alternativet

If sats efter where i SP

1 svar · 244 visningar · startad av Bjuris

BjurisMedlem sedan juli 2001514 inlägg
#1

Jag har en sp som är lite beroende av vad som kommer in.

Det är just where i min where som jag skulle vilja lägga en if sats då jag left joinar in en massa tabeller, men det är inte alltid jag vill plocka ut från dem.

ex:
Select customerName from customer_contact cc
left join System_reference SRP on SRP.OfficeID = CC.OfficeID
left join System_reference SRC on SRC.CustomerID = CC.CustomerID
WHERE
SRP.CustomerType = @Type1
OR
SRC.CustomerType = @Type2

Ibland så får jag in text på min @Type1 och ibland på min @Type2, men hur skall jag göra för att kolla om dem innehåller något, om de inte innehåller något så vill jag ju inte använda mig av dem

hade funderingar på:
if @Type1 <>''
SRP.CustomerType = @Type1
end

men det fungerar inte.

LarsGMedlem sedan dec. 200012 464 inlägg
#2
WHERE
(SRP.CustomerType = @Type1 or @type1 = '' or @type1 is null)
and
(SRC.CustomerType = @Type2 or @type1 = '' or @type1 is null)
125 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
121 ms — hämta tråd, inlägg och bilagor (db)