I need make a query on SQL Server 2005 to match this scenario, I have a varchar(max)
field with some id's like: "12323,12345,123,434345,2324,1211212
" and the user will give me a group, the first 3 numbers; So, in where clause I'll have to match each of this id separate by a comma, any suggestion? How can I do this?
product | id
prod01 1212,211,3434342,54532
prod02 323,323,424,5435,35345
prod03 2323,1212
@UserEntry='123'
You need a function to split the strings into separate values. Here's one. I don't know who wrote it originally, but it's been in our library since forever:
This will return the separate values as a table variable, from which you can use
IF @UserEntry IN ...