SQL Server Forums
Profile | Register | 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?
 New Topic  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
17439 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
52249 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  
 New 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.05 seconds. Powered By: Snitz Forums 2000