J
Jeff via AccessMonster.com
I have a stored procedure that I use to return a filtered list but I’m having
a problem with null values returned with joined tables. Here’s my code:
@Tbl1Var1 As nvarchar(50), @ Tbl1Var2 As nvarchar(50), @ Tbl1Var3 As nvarchar
(50), @Tbl1Var4 As nvarchar(50), @ Tbl1Var5 As nvarchar(50), @ Tbl2Var1 As
nvarchar(50)
AS
SELECT * FROM Tbl1 WHERE ID in
(SELECT ID FROM Tbl1
LEFT OUTER JOIN Tbl2 ON Tbl1.ID=Tbl2.ID
WHERE
Tbl1Var1 LIKE @Tbl1Var1 AND
Tbl1Var2 LIKE @Tbl1Var2 AND
Tbl1Var3 LIKE @Tbl1Var3 AND
Tbl1Var4 LIKE @Tbl1Var4 AND
Tbl1Var5 LIKE @Tbl1Var5 AND
Tbl2Var1 LIKE @Tbl2Var1)
Tbl1 and Tbl2 have a one to many relationship but if I set Tbl2Var = %
(wildcard) I only get back those records for which Tbl2Var1 Is Not Null.
Removing the last line (Tbl2Var1 LIKE @Tbl2Var) with all the other variables
= % returns the correct number of records.
I’m guessing I need an if statement to check for Tbl2var1 = null but my
attempts are proving unsuccessful. Any help is appreciated.
a problem with null values returned with joined tables. Here’s my code:
@Tbl1Var1 As nvarchar(50), @ Tbl1Var2 As nvarchar(50), @ Tbl1Var3 As nvarchar
(50), @Tbl1Var4 As nvarchar(50), @ Tbl1Var5 As nvarchar(50), @ Tbl2Var1 As
nvarchar(50)
AS
SELECT * FROM Tbl1 WHERE ID in
(SELECT ID FROM Tbl1
LEFT OUTER JOIN Tbl2 ON Tbl1.ID=Tbl2.ID
WHERE
Tbl1Var1 LIKE @Tbl1Var1 AND
Tbl1Var2 LIKE @Tbl1Var2 AND
Tbl1Var3 LIKE @Tbl1Var3 AND
Tbl1Var4 LIKE @Tbl1Var4 AND
Tbl1Var5 LIKE @Tbl1Var5 AND
Tbl2Var1 LIKE @Tbl2Var1)
Tbl1 and Tbl2 have a one to many relationship but if I set Tbl2Var = %
(wildcard) I only get back those records for which Tbl2Var1 Is Not Null.
Removing the last line (Tbl2Var1 LIKE @Tbl2Var) with all the other variables
= % returns the correct number of records.
I’m guessing I need an if statement to check for Tbl2var1 = null but my
attempts are proving unsuccessful. Any help is appreciated.