SELECT *
FROM sales
WHERE STUFF( LEFT(sales_id , CHARINDEX('-', sales_id , CHARINDEX('-', sales_id ) + 1) - 1),
1,
CHARINDEX('-', sales_id ) ,
'') = '4562'
The logic is to extract characters till second '-' from the LEFT and replace characters till first '-' ( including first '-') with a blank character ( '' ) . This may work faster than the previous one if your table is large.
ASKER
Select * from sales
Where sales_id like '%-4562-%’
Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.
TRUSTED BY
Where sales_id like '%4562%’
Revised...