Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to create SELECT for following rows in table?

Author  Topic 

FredFlinstone
Starting Member

2 Posts

Posted - 2014-10-20 : 04:15:53
hi friends,
please help me ... I have two db-tables:
"TAB01" with structure:

CREATE TABLE TAB01 (
ID int NOT NULL,
Name varchar(64) DEFAULT NULL,
PRIMARY KEY (ID)
)

It contains only name of some object.
And "TAB02" with structure:

CREATE TABLE TAB02 (
ID int NOT NULL,
TAB01_ID int NOT NULL,
PositionA int,
PositionB int,
StringVal varchar(32) DEFAULT NULL,
PRIMARY KEY (ID)
)

which contains following data:

ID|TAB01_ID|PositionA|PositionB|StringVal|
1|1|1|1|A|
2|1|1|2|B|
3|1|1|3|C|
4|1|1|4|D|
5|1|1|5|E|
6|1|1|6|A|
7|1|1|7|D|
8|2|2|1|J|
9|2|2|2|K|
10|2|2|3|A|
11|2|2|4|B|
12|2|2|5|F|
13|2|2|6|F|
14|2|2|7|B|
15|3|3|1|B|
16|3|3|2|A|
17|3|3|3|C|
18|3|3|4|A|
19|3|3|5|F|
20|3|3|6|G|
21|3|3|7|A|
22|3|3|8|F|
23|4|4|1|F|
24|4|4|2|E|
25|4|4|3|A|
26|4|4|4|B|
27|4|4|5|B|
28|4|4|6|E|
29|4|4|7|E|
30|5|5|1|A|
31|5|5|2|B|
32|5|5|3|C|
33|5|5|4|B|
34|5|5|5|A|
35|5|5|6|D|
36|5|5|7|A|
37|5|5|8|B|
38|6|6|1|D|
39|6|6|2|E|
40|6|6|3|F|
41|6|6|4|A|
42|6|6|5|B|
43|6|6|6|A|
44|6|6|7|F|
45|7|7|1|A|
46|7|7|2|A|
47|7|7|3|B|
48|7|7|4|B|
49|7|7|5|E|
50|7|7|6|B|
51|7|7|7|E|
...

and I need to find a sequence of values in column "StringVal", for example: A B
I look for a suitable SELECT, that returns (in this case) following result:

TAB02.ID|TAB01.Name|TAB02.PositionA|TAB02.PositionB|
1|ABC|1|1|
10|DEF|2|3|
25|JKL|4|3|
30|MNO|5|1|
36|MNO|5|7|
41|PQR|6|4|
46|STU|7|2|
...


For information:
Data inserted in "TAB02" represents real-life structure:

ID|Name|P01|P02|P03|...|Pxy|
1|ABC|A|B|C|D|E|A|D|
2|DEF|J|K|A|B|F|F|B|
3|GHI|B|A|C|A|F|G|A|F|
4|JKL|F|E|A|B|B|E|E|
5|MNO|A|B|C|B|A|D|A|B|
6|PQR|D|E|F|A|B|A|F|
7|STU|A|A|B|B|E|B|E|


Thank for any advice and help.

FredFlinstone
Starting Member

2 Posts

Posted - 2014-10-20 : 04:24:44
... simply saying:

If you search sequence "AB", it starts on row TAB02.ID=1, then on TAB02.ID=10, then on TAB02.ID=25, then 30, 36, 41, ...
Go to Top of Page
   

- Advertisement -