Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / July 2005

Tip: Looking for answers? Try searching our database.

Help with this Stored Procedure

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff - 21 Jul 2005 18:44 GMT
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.
Sylvain Lafontaine - 21 Jul 2005 19:20 GMT
You need something like:

... (Tble2Var1 is Null OR Tbl2Var1 LIKE @Tbl2Var1) ...

Signature

Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC

> I have a stored procedure that I use to return a filtered list but I'm
> having
[quoted text clipped - 24 lines]
> I'm guessing I need an if statement to check for Tbl2var1 = null but my
> attempts are proving unsuccessful. Any help is appreciated.
Jeff - 22 Jul 2005 17:20 GMT
the only problem with that is that if specify a specific value for @tbl2Var1
I will also get null records which I don't want.

>You need something like:
>
[quoted text clipped - 5 lines]
>> I'm guessing I need an if statement to check for Tbl2var1 = null but my
>> attempts are proving unsuccessful. Any help is appreciated.
Sylvain Lafontaine - 22 Jul 2005 17:53 GMT
First, you should be able to fine tune this without any problem by adding
all the required logical comparaisons that will suit your exact needs.

Second, I don't see the logic of using a Left Outer Join if you are not
interested with Null values on the right side.

Signature

Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC

> the only problem with that is that if specify a specific value for
> @tbl2Var1
[quoted text clipped - 9 lines]
>>> I'm guessing I need an if statement to check for Tbl2var1 = null but my
>>> attempts are proving unsuccessful. Any help is appreciated.
Jeff - 25 Jul 2005 16:31 GMT
I am interested in the null values in certain cases (i.e. wildcard should
return all records from left side). I thought the solution would be a lot
easier but I guess I'll have to re-think this one.

>First, you should be able to fine tune this without any problem by adding
>all the required logical comparaisons that will suit your exact needs.
[quoted text clipped - 7 lines]
>>>> I'm guessing I need an if statement to check for Tbl2var1 = null but my
>>>> attempts are proving unsuccessful. Any help is appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.