---
title: "If sats efter where i SP"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/142470-if-sats-efter-where-i-sp"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "Bjuris"
published: "2006-02-14T07:01:54.000Z"
updated: "2006-02-14T08:31:26.000Z"
replies: 1
views: 246
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/databaser-sql/142470-if-sats-efter-where-i-sp"
---

# If sats efter where i SP

## #1 — Bjuris, 2006-02-14T07:01Z

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.

Permalänk: https://www.webforum.nu/p/142470

## #2 — LarsG, 2006-02-14T08:31Z

```
WHERE
(SRP.CustomerType = @Type1 or @type1 = '' or @type1 is null)
and
(SRC.CustomerType = @Type2 or @type1 = '' or @type1 is null)
```

Permalänk: https://www.webforum.nu/p/1767947

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/142470-if-sats-efter-where-i-sp
