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.
| Author |
Topic |
|
Billmiles77
Starting Member
7 Posts |
Posted - 2012-10-17 : 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
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-17 : 22:45:44
|
sounds like this:-SELECT t.account_noFROM (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' )tLEFT JOIN master_table mON m.account_no = t.account_noWHERE m.ccount_no IS NULL ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Billmiles77
Starting Member
7 Posts |
Posted - 2012-10-18 : 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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-18 : 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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Reading this I think you're good to go with my suggestion------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Billmiles77
Starting Member
7 Posts |
Posted - 2012-10-18 : 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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog
Reading this I think you're good to go with my suggestion------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-10-18 : 21:44:35
|
welcome ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|