my idea is to create a stored procedure which input is a string like 'A-B-C' or a precreated table with vertices in proper order ('A', 'B', 'C'). So you will have a loop and step by step you should walk through the path 'A-B-C'. For this you need a temp table for vertices on current step:
1)step 0
@currentLabel = getNextVertexLabel(...) --need to decide how to do this
select
*
into #v
from Vertices
where
vertexLabel = @currentLabel
--we need it later
select
*
into #tempV
from #v
where
0 <> 0
2)step i
@currentLabel = getNextVertexLabel(...)
insert #tempV
select
vs.*
from #v v
join Edges e on
e.SourceVertex = v.VertexID
and e.graphID = v.graphID
join Vertices vs on
e.destinationVertex = vs.VertexID
and e.graphID = vs.graphID
where
vs.vertexLabel = @currentLabel
truncate table #v
insert #v
select * from #tempV
truncate table #tempV
3)after loop
You result will store at #v. So the number of subgraphs will be:
select count(*) from #v