About this question
We receive an order list, and validate it starts with certain prefixes, for example if OrderNumber does not start with ABC, then display the order list to the user as error. We use exists, to search for first existence, don't want to consume much performance time. If none exist, then we can start conducting other task in code. Is there any way in sql to get rid of the repetitive code? We have Many checks like this on multiple tables, trying to make code more efficient.
if exists ( select * from dbo.OrdersImport where left(OrderNumber,3) <> 'ABC' ) begin select OrderNumber as OrderErrorList from dbo.OrdersImport where left(OrderNumber,3) <> 'ABC' end else