webForumDet fria alternativet

SP ifsats med valfri join

1 svar · 165 visningar · startad av Brimba

BrimbaMedlem sedan dec. 19995 875 inlägg
#1

Hej!

Jag har en SP som ser ut såhär

SELECT
   fields
FROM
   table
JOIN
   this and that
ON
   this and that
WHERE
   this and that = this and that

Nu skulle jag vilja ha joinen innanför en ifsats exempelvs:

SELECT
   fields
FROM
   table
if @myVar = 0
BEGIN
JOIN
   this and that
ON
   this and that
END
WHERE
   this and that = this and that

Men jag får bara fel när jag gör så, hur skall jag gå tillväga?

BrimbaMedlem sedan dec. 19995 875 inlägg
#2

Det verkar inte gå, jag löste det på ett annat sätt.

135 ms totalt · 3 externa anrop · v20260731065814-full.30151723
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
132 ms — hämta tråd, inlägg och bilagor (db)