0

code Table

code_grille code_grille_talend
s01         4 7 2 8   
s02         5 2 8 9 6 3 7   
s03         3 6 4 7 5 8 2   
s04         2 6 4 8 5 2 8 0  
s05         4 7 8 5 9 7 4 5 8 
s06         2 4 7 8 9 3 6 5  
s07         2 5 4 7 8 
s08         2 3 4 5 6 7 8 9  
s09         9 8 2 5 7 3 6 4  
s10         2 4 5 2 8 7 9 3 6 
s11         4 5 7 2 3 2 3 8  

commande table

code_commande   code_article    taille
001             1               s         
001             1               m         
001             1               xl        
001             1               x52       
001             2               m         
001             1               5566      
001             2               x52       
001             1               xl        
002             1               s         
002             2               m         
001             3               xxl   

code T table (result of the first query)

code

2         
3         
4         
1         
12            

I have two queries which I need to use the result of the first query in the second query dynamically. The first query returns much code which I need to put them in the second query to have resulted for each row.

I have load the result of the first query in a table but I have one result in the second query.

The first query is:

select [code_commande],[code_article],[code] 
from [dbo].[conversion],[dbo].[commande] 
where [dbo].[conversion].taille=[dbo].[commande].taille 
and code_article=? and code_commande=?

The second query is:

select top 1 (G.[code_grille_talend]), count(C.code) as counter
from [dbo].[code] G 
left  join [dbo].[codeT] C 
on G.code_grille_talend not like '%'+LTRIM(RTRIM(C.code))+'%'
group by G.code_grille_talend
having LEN(g.code_grille_talend)+count(C.code)<=40 or count(C.code)=0
order by len(g.code_grille_talend)desc

I have loaded the result of the first query in a table (codeT)

Razvan Socol
  • 5,426
  • 2
  • 20
  • 32
  • 1
    Please take a few moments and fix your formatting. Add _four_ or more spaces to each line of code/data. – Tim Biegeleisen Apr 07 '19 at 12:54
  • Also, please read the first two paragraphs of the [T-SQL tag info](https://stackoverflow.com/tags/tsql/info) and [edit] your question accordingly. – Zohar Peled Apr 07 '19 at 13:08

0 Answers0