How to get the children of a string according to the dot
I have code numbers as the following sequential:
1
1.1
1.2
1.3
.
.
.
1.1.1
1.1.2
.
.
.
2
And so..
I want a method to that parses the children based on some input. For example, if the input is 1
then it will retrieve all it's children, and if the input is 开发者_JAVA百科1.1
it will retrieve all of it's children, etc.
How can I do something like that?
Notes:
- This data is stored in one table in
Informix
database. - The code numbers are strings.
Code
var list = new List<string>();
var children = list.Where(s => s.StartsWith(inputString));
DB
DECLARE @p1 varchar(100)
SET @p1 = '1.1%'
SELECT * FROM tbl WHERE tbl.col LIKE @p1
SELECT ...
FROM yourtable
WHERE codestring LIKE '1.1%';
should do the trick.
Just to be different - using SUBSTR etc instead of LIKE:
SELECT *
FROM AnonymousTable
WHERE SUBSTR(CodeNumbers, 1, LENGTH(<xxx>)) = <xxx>;
Where the <xxx>
notation indicates where you place the argument. There are various notations for that, depending on exactly how the SQL is being handled. The one downside is that it requires two references to the same parameter value.
Will not a simple sql query solve it??
something like
SELECT * from the_table where column matches "input*"?
精彩评论