Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select statement

Author  Topic 

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-06-21 : 05:37:27
Hi,

I have the following code

SELECT     dbo.qryPracExclude.prac_no
FROM dbo.qryPracExclude LEFT OUTER JOIN
dbo.TblPracExclude ON dbo.qryPracExclude.prac_no = dbo.TblPracExclude.prac_no



qryPracExclude.prac_no = 1, 2, 3, 4
dbo.TblPracExclude.prac_no = 1, 2, 3


The results of the above gives me

prac_no
1
2
3

I want the result to give me;

prac_no
4


this prac_no is present in qryPracExclude.prac_no and not dbo.TblPracExclude.prac_no.

I tried <> instead of = but I receive duplicates and all prac_nos.

Any help will be appreciated


nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-06-21 : 05:54:01
Your query shoould give all 4 values from qryPracExclude so I think there is something wrong with that.
When you correct it.

SELECT dbo.qryPracExclude.prac_no
FROM dbo.qryPracExclude
LEFT OUTER JOIN dbo.TblPracExclude
ON dbo.qryPracExclude.prac_no = dbo.TblPracExclude.prac_no
where dbo.TblPracExclude.prac_no is null






==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

dr223
Constraint Violating Yak Guru

444 Posts

Posted - 2012-06-21 : 05:59:58
Many thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-06-21 : 17:52:45
also

SELECT q.prac_no
FROM dbo.qryPracExclude q
WHERE NOT EXISTS (SELECT 1 FROM dbo.TblPracExclude WHERE prac_no = q.prac_no)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -