Tesla Posted October 13, 2009 at 04:34 PM Report Share #291543 Posted October 13, 2009 at 04:34 PM Boas. Estou a tentar criar uma tabela resumo dinâmica. Ela deverá ter na primeira coluna os locais de venda, e nas colunas deverão ser as vendas por dia, onde o titulo de cada uma dessas colunas será o dia a que as vendas se reportam. Uma coisa deste género: [table][/table]De notar que onde temos os dias da semana, deveriam aparecer os dias do mês, de forma dinâmica. Obrigado pela vossa ajuda. 👍 Assinatura editada pelo staff, por favor consulte as regras. Link to comment Share on other sites More sharing options...
IceBrain Posted October 14, 2009 at 08:20 AM Report Share #291623 Posted October 14, 2009 at 08:20 AM "Dinâmica"? Mas queres alterar o esquema da tabela diariamente? Isso não é recomendável, imho. Faz uma tabela com a coluna POS e as colunas para cada dia do mês, e depois no programa que trabalhar com a BD, pedes só as colunas de dia 1 até ao dia actual. ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps Link to comment Share on other sites More sharing options...
Tesla Posted October 14, 2009 at 09:00 AM Author Report Share #291626 Posted October 14, 2009 at 09:00 AM Boas. Por dinâmica quero dizer que, onde diz Segunda Feira, coloque a data no formato DD-MM-AAAA. A ideia é ter uma tabela semanal de vendas. Se que a correr ela vai ver todas as vendas de todos os sites feitos entre a segunda feira dessa semana e o dia em que estamos dessa semana também. O meu problema está em conseguir com que o SQL crie as colunas dos dias e coloque lá os somatórios correctos. Obrigado, desde já, pelo interesse em ajudar! 🙂 Assinatura editada pelo staff, por favor consulte as regras. Link to comment Share on other sites More sharing options...
IceBrain Posted October 14, 2009 at 09:46 AM Report Share #291634 Posted October 14, 2009 at 09:46 AM Hmm, mesmo nesse caso, também não me parece que seja essa a melhor solução. Porque não fazes uma tabela: POS | Data | Vendas E depois o programa lê os dias que quer para a POS que quiser. Depois fazes um select entre duas datas: SELECT Vendas WHERE POS = Lisboa AND Data between ('2004-12-03') and ('2004-12-12') ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps Link to comment Share on other sites More sharing options...
Tesla Posted October 14, 2009 at 01:13 PM Author Report Share #291651 Posted October 14, 2009 at 01:13 PM Boas. Não me dá jeito criar tabelas para isso porque eu estou a trabalhar sobre uma BD PHC. Aquilo que me está a fazer falta é mesmo uma ajudinha no código de SQL, dados que isto já me parece ser de expert. :-) Abraço. Assinatura editada pelo staff, por favor consulte as regras. Link to comment Share on other sites More sharing options...
IceBrain Posted October 14, 2009 at 02:17 PM Report Share #291657 Posted October 14, 2009 at 02:17 PM Ah, pensei que estavas a fazer um programa de raiz. Sendo assim não te consigo ajudar 🙂 Se compraste uma solução de um distribuidor da PHC, devias enviar-lhes um email a expor o teu problema. Eles têm a obrigação de te suportar as adaptações que tu necessites para o teu negócio. ❝The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.❞- John Carmack on software patents A list of command line apps Link to comment Share on other sites More sharing options...
miro3 Posted October 14, 2009 at 04:42 PM Report Share #291670 Posted October 14, 2009 at 04:42 PM Não precisas de nenhuma tabela dinamica. Precisas sim de um codigo que coloque o total do dia em coluna/semana/mes/ano vê o seguinte codigo sobre uma BD PHC e adapta-o às tuas necessidades (este codigo é para procurar compras por mês para o presente ano). Se não quiseres fazer isto em SQL deves então usar o VFP do lado do client. PS: sempre podes pedir ajudar na comunidade da phc, pode ser que te safes .... 🙂 TSQL ... DECLARE @ref_1 CHAR(18) DECLARE c_1 Cursor For Select Distinct top 1 Ref From St (Nolock) OPEN c_1 FETCH NEXT FROM c_1 INTO @ref_1 WHILE @@Fetch_status = 0 BEGIN BEGIN TRANSACTION If (select count(*) From fn (Nolock) inner join fo (Nolock) on fo.fostamp=fn.fostamp inner join cm1 (Nolock) on cm1.cm=fo.doccode where Fn.ref=@Ref_1)>0 Begin Insert Into #1 select Distinct st.REF, st.Design, st.unidade, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=1 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) Janeiro, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=2 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) fevereiro, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=3 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) Março, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=4 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) abril, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=5 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) maio, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=6 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) junho, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=7 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) julho, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=8 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) julho, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=9 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) agosto, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=10 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) setembro, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=11 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) outubro, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) And Month(datalc)=12 and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) novembro, Isnull((Select sum(qtt) from Sl (Nolock) Where year(datalc)=Year(getdate()) and ref=@ref_1 and cm in (1,2,5,9,13,14) ),0) dezembro from St (Nolock) where st.ref=@Ref_1 group by st.REF, st.design, st.unidade order by st.REF End FETCH NEXT FROM c_1 INTO @ref_1 COMMIT TRANSACTION END CLOSE c_1 DEALLOCATE c_1 ... Link to comment Share on other sites More sharing options...
M6 Posted October 15, 2009 at 08:34 AM Report Share #291726 Posted October 15, 2009 at 08:34 AM Criar ou alterar uma tabela "on the fly" é fácil, o problema aqui é que me parece que estás a ter um erro de lógica e o que queres é uma linha e não uma nova coluna na tabela, tal como o IceBrain já referiu. Estás a construir um "mini data warehouse" ou algo assim? Isso que estás a referir soa muito ao cruzamento de uma tabela de factos com uma tabela de dimensão... 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." 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