We receive an order list, and validate it starts with certain prefixes, example if OrderNumber does not start with ABC, than display order list to 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 anyway 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