| Author |
Topic  |
|
|
Billmiles77
Starting Member
7 Posts |
Posted - 10/17/2012 : 17:05:28
|
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
35007 Posts |
|
|
tkizer
Almighty SQL Goddess
USA
35007 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 10/17/2012 : 22:45:44
|
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/
|
 |
|
|
Billmiles77
Starting Member
7 Posts |
Posted - 10/18/2012 : 10:30:27
|
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
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 10/18/2012 : 12:56:42
|
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/
|
 |
|
|
Billmiles77
Starting Member
7 Posts |
Posted - 10/18/2012 : 17:16:19
|
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/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
India
47023 Posts |
Posted - 10/18/2012 : 21:44:35
|
welcome 
------------------------------------------------------------------------------------------------------ SQL Server MVP http://visakhm.blogspot.com/
|
 |
|
| |
Topic  |
|