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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query WHERE statement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Billmiles77
Starting Member

7 Posts

Posted - 10/17/2012 :  17:05:28  Show Profile  Reply with Quote
I am executing a SQL query, via Toad, that is searching a table based on accounts that are part an 'IN" list within the WHERE statement.
Can I flag accounts that are not found in the DB based on the WHERE 'IN' list accounts?

SELECT account_no
FROM master_table
WHERE (account_no IN ( 01, 02, 03, 04, 05, 06));

tkizer
Almighty SQL Goddess

USA
36932 Posts

Posted - 10/17/2012 :  17:48:41  Show Profile  Visit tkizer's Homepage  Reply with Quote
I'm not sure I understand. Are you looking for NOT IN?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
36932 Posts

Posted - 10/17/2012 :  17:48:54  Show Profile  Visit tkizer's Homepage  Reply with Quote
A small data example might make the post more clear. Thank you.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/17/2012 :  22:45:44  Show Profile  Reply with Quote
sounds like this:-


SELECT t.account_no
FROM (SELECT '01' AS account_no
      UNION ALL
      SELECT '02' 
      UNION ALL 
      SELECT '03'
      UNION ALL 
      SELECT '04'
      UNION ALL
      SELECT '05'
      UNION ALL
      SELECT '06'
      )t
LEFT JOIN master_table m
ON m.account_no = t.account_no
WHERE m.ccount_no IS NULL


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

Go to Top of Page

Billmiles77
Starting Member

7 Posts

Posted - 10/18/2012 :  10:30:27  Show Profile  Reply with Quote
Firstly, Thank you for the reply and time. What I am really looking for is when using the 'WHERE IN' list if an account is not found in the query based on the list can that account, not found, somehow be flag and reported on the output? example "WHERE (account_no IN ( 01, 02, 03, 04, 05, 06));". If during the query excution account 01, 02, 03, 05 and 06 are found in the table however 04 is not, can I somehow still report that the account was not found in the table on the output? (without doing some manual compares of the accounts included in the "WHERE IN " statement to those not reported(not found)?
quote:
Originally posted by tkizer

A small data example might make the post more clear. Thank you.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/18/2012 :  12:56:42  Show Profile  Reply with Quote
quote:
Originally posted by Billmiles77

Firstly, Thank you for the reply and time. What I am really looking for is when using the 'WHERE IN' list if an account is not found in the query based on the list can that account, not found, somehow be flag and reported on the output? example "WHERE (account_no IN ( 01, 02, 03, 04, 05, 06));". If during the query excution account 01, 02, 03, 05 and 06 are found in the table however 04 is not, can I somehow still report that the account was not found in the table on the output? (without doing some manual compares of the accounts included in the "WHERE IN " statement to those not reported(not found)?
quote:
Originally posted by tkizer

A small data example might make the post more clear. Thank you.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog




Reading this I think you're good to go with my suggestion

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

Go to Top of Page

Billmiles77
Starting Member

7 Posts

Posted - 10/18/2012 :  17:16:19  Show Profile  Reply with Quote
Thanks again...I will give this a shot and let you know the results..
quote:
Originally posted by visakh16

quote:
Originally posted by Billmiles77

Firstly, Thank you for the reply and time. What I am really looking for is when using the 'WHERE IN' list if an account is not found in the query based on the list can that account, not found, somehow be flag and reported on the output? example "WHERE (account_no IN ( 01, 02, 03, 04, 05, 06));". If during the query excution account 01, 02, 03, 05 and 06 are found in the table however 04 is not, can I somehow still report that the account was not found in the table on the output? (without doing some manual compares of the accounts included in the "WHERE IN " statement to those not reported(not found)?
quote:
Originally posted by tkizer

A small data example might make the post more clear. Thank you.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog




Reading this I think you're good to go with my suggestion

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



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 10/18/2012 :  21:44:35  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
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.09 seconds. Powered By: Snitz Forums 2000