In my query I need to return distinct fields for my search. However the txt_note field returns info even if there is none.
SELECT DISTINCT T_ORDER_DETAIL.TXT_ORDER_NUMBER,
T_ORDER_DETAIL.CUSTOMER_PRODUCT_ID,
T_VENDOR.VENDOR_ID,
T_CUSTOMER_ACCOUNT.CUSTOMER_ID,
T_EMPLOYEE.TXT_EMAIL,
T_ORDER_ASSIGNMENT.TXT_NOTE
FROM T_VENDOR_EMPLOYEE
INNER JOIN T_VENDOR WITH(nolock)
ON T_VENDOR_EMPLOYEE.VENDOR_ID = T_VENDOR.VENDOR_ID
INNER JOIN T_CUSTOMER_ACCOUNT WITH(nolock)
INNER JOIN T_ORDER_DETAIL WITH(nolock)
INNER JOIN T_CUSTOMER_PRODUCT WITH(nolock)
ON T_ORDER_DETAIL.CUSTOMER_PRODUCT_ID =
T_CUSTOMER_PRODUCT.CUSTOMER_PRODUCT_ID
ON T_CUSTOMER_ACCOUNT.CUSTOMER_ACCOUNT_ID =
T_CUSTOMER_PRODUCT.CUSTOMER_ACCOUNT_ID
ON T_VENDOR_EMPLOYEE.VENDOR_EMPLOYEE_ID =
T_ORDER_DETAIL.VENDOR_EMPLOYEE_ID
INNER JOIN T_EMPLOYEE WITH(nolock)
ON T_VENDOR_EMPLOYEE.EMPLOYEE_ID = T_EMPLOYEE.EMPLOYEE_ID
INNER JOIN T_ORDER_DETAIL_REJECTION_REASON WITH(nolock)
ON T_ORDER_DETAIL.ORDER_DETAIL_ID =
T_ORDER_DETAIL_REJECTION_REASON.ORDER_DETAIL_ID
INNER JOIN T_ORDER_ASSIGNMENT WITH(nolock)
ON T_VENDOR_EMPLOYEE.VENDOR_EMPLOYEE_ID =
T_ORDER_ASSIGNMENT.VENDOR_EMPLOYEE_ID
WHERE T_ORDER_ASSIGNMENT.INT_ACCEPTED = 4
AND T_ORDER_ASSIGNMENT.TXT_NOTE <> ''
Even though it returns info, when you look at the actual order that field is blank.
txt_Order_Number Customer_Product_ID vendor_ID customer_id txt_email txt_Note
260247648 555 134242 650 jason@propertysmart.us Out of office
260498186 2783 134242 429 jason@propertysmart.us Out of office
261108453b 1485 134242 206 jason@propertysmart.us Out of office
261240252b 4429 134242 206 jason@propertysmart.us Out of office
270158583b 4429 134242 206 jason@propertysmart.us Out of office
270877727 3190 134242 724 jason@propertysmart.us Out of office
271239690b 4817 134242 486 jason@propertysmart.us Out of office
280162866b 5378 134242 721 jason@propertysmart.us Out of office
280968017b 1485 134242 206 jason@propertysmart.us Out of office
290702640 9361 134242 120 jason@propertysmart.us Out of office
291294922-50 9972 134242 977 jason@propertysmart.us Out of office
300453305-25 3648 134242 206 jason@propertysmart.us Out of office
301297011-50 1922 134242 206 jason@propertysmart.us Out of office
only one of the txt_not actually has out of office in it and the rest are blank.
any help is greatly appreciated.
Thanks
I would try simplifying the query, starting with as few inner joins as possible. Ie:
If this gives the expected result, add more inner joins until you get your error – then look at the data and see if you can identify the cause.
Also, are you aware that your use of WITH (NOLOCK) might cause you to miss committed rows?
http://blogs.msdn.com/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx