views:

49

answers:

2

Hy guys, my question is: if i have in asp.net, a SqlDatasource or AccessDatasource with the following select command: SELECT * FROM Mytable WHERE SomeFieldID=@FilterID

SomefieldID is an integer

And i would like to use the jolly char (* or %) to show all datas... how can i do?

Thanks to everybody will help...

Bye Stighy

A: 

Do you mean the LIKE statement?

SELECT * FROM Mytable WHERE cast(SomeFieldID AS varchar(100)) LIKE '%' + @FilterID + '%'

This will return any record that contains the contents of FilterID.

Assuming FilterID is a string.

Matthew Jones
+1  A: 

It seems like a classic case of "when all you have is a hammer, everything looks like a nail". If you are trying to match "1%%" you actually mean >=100 and <=199. Similarly, when you try to match SomeFieldID LIKE "*3", you actually meant SomeFieldID % 10 = 3.

MSalters