Jump to content

Ajuda em filtro SQL


HQuintas

Recommended Posts

Dim sqlT = "SELECT linha,id FROM Tabela1 as S where exists" & _
            "(select id from Tabela3 where S.id=tabela3.id) AND S.serv='N1' AND S.chk=0 ORDER BY S.data AND " & _
            "(Select id FROM Tabela2 WHERE (Tabela2.TIPO='A' OR Tabela2.TIPO='B') AND CONVERT(nvarchar(10),Tabela2.data, 105)='" & diaSeg & "';"

Queria fazer um filtro de 3 tabelas

Seleccionar ID que exista na tabela3 que na tabela1 faça serv=N1 ordenado por data e que da tabela2 seja do tipo A ou B no diaseg.

É possivel? como?

Obrigado

Link to post
Share on other sites
ricardotrindade

O teu português está um bocado confuso. Pelo que percebi, querias algo assim, será?

SELECT S.linha, S.id
FROM Tabela1 as S
INNER JOIN TABELA3 T3 ON (T3.ID = S.ID AND S.SERV = 'N1')
INNER JOIN TABELA2 T2 ON (T2.ID = S.ID AND T2.TIPO IN ('A','B'))
ORDER BY S.DATA;

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.