mostrar filas que contienen "#Error" en el resultado de la consulta

I have a right join query (joining a table and another query output). I get "#Error" displayed in some rows. Is there a way to just display the rows which give "#Error" ?

Aquí está mi consulta:

SELECT Table1.Number1, Table2.Number2
FROM Table2 RIGHT JOIN Table1 ON Table2.Number2 = Table1.Number1;

Data de muestra:

Expr1   Expr2
2346    2346
2347    2347
2348    #Error
2349    2349
2350    2350
2351    2351

Sub Query:

SELECT Val(Right([String2],Len([String2])-8)) AS Number2
FROM Table3;

Gracias por adelantado

preguntado el 09 de marzo de 12 a las 16:03

Please show some of the data that results in #Error. -

@rontornambe updated with sample data -

How about showing us the sub-query too? -

@rontornambe updated with sub query -

Looks to me like the #Error is occurring because your subquery is performing two operations that occasionally fail. The "Right" could fail if the string is 8 or fewer characters in length. The "Val" could fail if the substring isn't numeric. If you want to see just #Error rows, then query for items that would cause either of those conditions. If you don't want Errors, then do an INNER JOIN instead. -

1 Respuestas

Just add a WHERE clause on the end. Should work fine. If you have multiple columns that the #ERROR rows might show up in, use a WHERE clause with ORs (or, alternately, ||s ) in it. If you toss out a clearer idea of which columns have #ERRORs in them, I could batch you together a code block for it, but it should be pretty easy for you to handle for yourself.

Edit: Correction:

SELECT Table1.Number1
FROM Table1
WHERE Table1.Number1 NOT IN (
    SELECT Table2.Number2 FROM Table2
)

You're getting errors because you're forcing table1 to show up even where there's nothing in table 2 to match it. This will give you the orphans.

respondido 09 mar '12, 16:03

how would that fix the #Error? - Taryn

He didn't ask to fix the things. He asked to display them. Why do you downvote me for answering the question the OP asked? - ben barden

This answer is not useful. What would the asker need in their where clause? Just as with questions, answers need to have a certain amount of specificity. - justin pihony

Given the user's question, I had assumed that the #ERROR was showing up in specific columns. What would be the point of displaying just a list of identical rows? Given that I didn't have the columns to work with, I couldn't write up the WHERE clause myself, could I? - ben barden

@BenBarden I didn't do the downvote, I just commented on your original answer. - Taryn

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.