A_T_C Posted October 31, 2009 at 05:24 PM Report Share #294181 Posted October 31, 2009 at 05:24 PM Boa tarde! Preciso de comparar valores q se encontram em tabelas distintas... Por exemplo, Tabela1 : id | Data 1 |01092009 2 | 23072005 Tabela2 id | Dia | Mes | Ano 1 | 01 | 09 | 2009 4 |12 | 02 | 2020 e neste caso queria comparar as datas e verificar quais sao iguais... Qual a melhor forma de o fazer? ? Link to comment Share on other sites More sharing options...
bruno1234 Posted October 31, 2009 at 05:55 PM Report Share #294182 Posted October 31, 2009 at 05:55 PM Tens que converter os dados da segunda tabela numa string. Tens aqui um exemplo de como obter o resultado que queres em SQL Server: declare @T1 table( id int, data varchar(20) ) declare @T2 table( id int, dia tinyint, mes tinyint, ano smallint ) insert into @T1 values (1, '01092009') insert into @T1 values (2, '23072005') insert into @T2 values (1, 1,9,2009) insert into @T2 values (2, 12,2,2020) select b.id, b.dia, b.mes, b.ano from @T1 a inner join @T2 b on a.data = REPLICATE('0', 2 - LEN(b.dia)) + cast(b.dia as varchar(2)) + REPLICATE('0', 2 - LEN(b.mes)) + cast(b.mes as varchar(2)) + REPLICATE('0', 4 - LEN(b.ano)) + cast(b.ano as varchar(4)) Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
A_T_C Posted October 31, 2009 at 07:09 PM Author Report Share #294185 Posted October 31, 2009 at 07:09 PM REPLICATE tb é usado no Postgres? Link to comment Share on other sites More sharing options...
bruno1234 Posted October 31, 2009 at 07:11 PM Report Share #294186 Posted October 31, 2009 at 07:11 PM Não sei, provavelmente não. Mas o que faz até podes fazer manualmente, q é acrescentar um 0 do lado esquerdo qd o valor da data é menor que 10. Podes fazer com um case. Matraquilhos para Android. Gratuito na Play Store. https://play.google.com/store/apps/details?id=pt.bca.matraquilhos Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now