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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to use NOT IN clause within this join table?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

coolbear91
Starting Member

2 Posts

Posted - 12/19/2012 :  02:57:02  Show Profile  Reply with Quote
hi guys,
I'm using some query to try to display the case below:

table A has 100 rows
result A = 100 rows, comes from table A with all [CP_LOAD%] values
result B = 25 rows, comes from table A which have [CP_LOAD%] > 100
result C = 75 rows, comes from table A which have [CP_LOAD%] <= 100

the query is as below:



SELECT A.[Week] 
      ,A.[DATE] 
      ,A.[Time] 
      ,A.[ACCLOAD] 
      ,A.[NSCAN] 
      ,A.[exchid] 
      ,A.[CP_LOAD%]CP_LOAD 
  FROM [BLADE_MJK29].[dbo].[dz_cpload] A 
   WHERE
(
      [Week] 
      ,[DATE] 
      ,[Time] 
      ,[ACCLOAD] 
      ,[NSCAN] 
      ,[exchid] 
      ,[CP_LOAD%]
) 
    NOT IN 
      ( 
  SELECT 
  max([CP_LOAD%])CP_LOAD 
  FROM [BLADE_MJK29].[dbo].[dz_cpload] 
  group by [Week] 
      ,[DATE] 
      ,[Time] 
      ) 


when I run it, it returns an error message like this:

Msg 4145, Level 15, State 1, Line 12
An expression of non-boolean type specified in a context where a condition is expected, near ','.


what does it means?
and how should I fix the script then?

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 12/19/2012 :  03:12:27  Show Profile  Reply with Quote

WHERE A.[CP_LOAD%] NOT IN 
(
  SELECT 
          max([CP_LOAD%]) CP_LOAD 
  FROM   [BLADE_MJK29].[dbo].[dz_cpload] 
  group by [Week] 
          ,[DATE] 
          ,[Time] 
)



KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 12/19/2012 :  03:17:33  Show Profile  Reply with Quote
solution based on join

SELECT A.[Week] 
      ,A.[DATE] 
      ,A.[Time] 
      ,A.[ACCLOAD] 
      ,A.[NSCAN] 
      ,A.[exchid] 
      ,A.[CP_LOAD%] AS CP_LOAD 
  FROM [BLADE_MJK29].[dbo].[dz_cpload] A 
   LEFT JOIN  
      ( 
  SELECT [Week] 
      ,[DATE] 
      ,[Time]
  ,max([CP_LOAD%])CP_LOAD 
  FROM [BLADE_MJK29].[dbo].[dz_cpload] 
  group by [Week] 
      ,[DATE] 
      ,[Time] 
      )t1 
ON t1.[Week] = A.[Week]
AND t1.[DATE] = A.[DATE]
AND t1.[Time] = A.[Time]
AND  t1.CP_LOAD = A.[CP_LOAD%]
WHERE t1.[Week] IS NULL


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.36 seconds. Powered By: Snitz Forums 2000