Ir para conteúdo
Fórum Script Brasil

Pesquisar na Comunidade

Mostrando resultados para as tags ''case''.

  • Pesquisar por Tags

    Digite tags separadas por vírgulas
  • Pesquisar por Autor

Tipo de Conteúdo


Fóruns

  • Programação & Desenvolvimento
    • ASP
    • PHP
    • .NET
    • Java
    • C, C++
    • Delphi, Kylix
    • Lógica de Programação
    • Mobile
    • Visual Basic
    • Outras Linguagens de Programação
  • WEB
    • HTML, XHTML, CSS
    • Ajax, JavaScript, XML, DOM
    • Editores
  • Arte & Design
    • Corel Draw
    • Fireworks
    • Flash & ActionScript
    • Photoshop
    • Outros Programas de Arte e Design
  • Sistemas Operacionais
    • Microsoft Windows
    • GNU/Linux
    • Outros Sistemas Operacionais
  • Softwares, Hardwares e Redes
    • Microsoft Office
    • Softwares Livres
    • Outros Softwares
    • Hardware
    • Redes
  • Banco de Dados
    • Access
    • MySQL
    • PostgreSQL
    • SQL Server
    • Demais Bancos
  • Segurança e Malwares
    • Segurança
    • Remoção De Malwares
  • Empregos
    • Vagas Efetivas
    • Vagas para Estágios
    • Oportunidades para Freelances
  • Negócios & Oportunidades
    • Classificados & Serviços
    • Eventos
  • Geral
    • Avaliações de Trabalhos
    • Links
    • Outros Assuntos
    • Entretenimento
  • Script Brasil
    • Novidades e Anúncios Script Brasil
    • Mercado Livre / Mercado Sócios
    • Sugestões e Críticas
    • Apresentações

Encontrar resultados em...

Encontrar resultados que...


Data de Criação

  • Início

    FIM


Data de Atualização

  • Início

    FIM


Filtrar pelo número de...

Data de Registro

  • Início

    FIM


Grupo


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Encontrado 12 registros

  1. caros, boa noite! Tenho um select que retorna o valor de frete conforme unidade. Abaixo, as unidades '0001', '0002' e '0003' retornam algum valor, pois há registros na consulta. Na unidade '0004' o valor retornado é 'x' (alias do select), pois NÃO há nenhum registro dessa unidade nesse mês. Como faço para que quando escolhido a unidade '0004', seja retornado o valor ZERO? SELECT (ISNULL(valor_admfin.fat_admfin,0)) AS x FROM (SELECT CASE cte.unidade_codigo WHEN '0001' THEN ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_admce FROM CAD_PARAMETRO)/100 + ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_fince FROM CAD_PARAMETRO)/100 WHEN '0002' THEN ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_admpe FROM CAD_PARAMETRO)/100 + ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_finpe FROM CAD_PARAMETRO)/100 WHEN '0003' THEN ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_admsp FROM CAD_PARAMETRO)/100 + ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_finsp FROM CAD_PARAMETRO)/100 WHEN '0004' THEN ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_admpe FROM CAD_PARAMETRO)/100 + ISNULL(SUM(ISNULL(cte.total_frete,0)),0) * (SELECT taxa_finpe FROM CAD_PARAMETRO)/100 END AS fat_admfin FROM dbo.CONTRATO_FRETE c INNER JOIN viagens v ON c.pk_contrato_frete = v.fk_contrato_frete INNER JOIN consulta_cte cte ON v.viagem = cte.viagem INNER JOIN cad_filial f ON c.cod_unidade = f.codigo INNER JOIN dbo.cad_mes m ON month(c.emissao) = m.codigo WHERE year(c.emissao) = '2016' AND month(c.emissao) = '06' AND cte.unidade_codigo = '0004' AND c.des_status <> 'Cancelado' AND cte.cancelado <> 'Sim' GROUP BY cte.unidade_codigo ) AS valor_admfin
  2. Boa tarde, sou novo em VBA e ainda estou aprendendo algumas coisa. procurei em alguns lugares porem não consegui resolver o problema que um das informações apresenta o codigo abaixo sempre apresenta erro 13 ao indicar o mês 6, basicamente o relatório busca informações e resume em outro arquivo. e para todos os outros meses a info vem correta exceto o mês 6, lembrando que a referencia do mês é colocada por numeros ex: 01 - janeiro e assim por diante. alguém consegue me da alguma ajuda nisso? Código: Option Explicit Sub Turno() Dim i As Long, j As Long, k As Long, m As Long, s As Long, t As Byte Dim EscalaLr As Long, MesaLr As Long, BaseLr As Long Dim EscalaLc As Long, MesaLc As Long, BaseLc As Long, DadosLc As Byte Dim TabelaLr As Byte, TabelaLc As Byte Dim ApontarJorLr As Long Dim ApontarPreLr As Long Dim Linha As Long Dim Mais As Byte Dim MudarTurno As Byte Dim MesInput As String Dim Ano As Byte, Mes As Byte Dim MesaIni(6) As Byte, MesaFin(6) As Byte Dim Turnos(3) As String, TurnoNum(3) As Byte Dim ContarPre(3) As Integer Dim ContarPreM(6) As Integer, ContarPreT(6) As Integer, ContarPreN(6) As Integer, ContarPreF(6) As Integer Dim ContarJor(3) As Integer Dim ContarJorM(6) As Integer, ContarJorT(6) As Integer, ContarJorN(6) As Integer, ContarJorF(6) As Integer Dim SupIni As Byte, SupFin As Byte Dim QtTec As Byte, QtSup As Byte Dim NomeTec() As String, NomeSup() As String Dim ClmTec() As Byte, ClmSup() As Byte Dim DataM, DataE As Byte Dim Dados As Workbook Dim TabJor As Byte, TabMed As Byte, TabPre As Byte, TabSbr As Byte, TabPtr As Byte, TabPar As Byte, TabEsp As Byte Application.ScreenUpdating = False Application.DisplayAlerts = False Ano = 16 MesInput = InputBox("De qual mês deseja rodar o indicador", "Monitoramento de Escala") Mes = MesInput Tabela.Cells(1, 2) = Mes Tabela.Cells(1, 2).Font.Color = vbBlack Tabela.Cells(1, 2).HorizontalAlignment = xlCenter For i = 0 To 5 If i <= 3 Then ContarPre(i) = 0 ContarJor(i) = 0 End If ContarPreM(i) = 0 ContarPreT(i) = 0 ContarPreN(i) = 0 ContarPreF(i) = 0 ContarJorM(i) = 0 ContarJorT(i) = 0 ContarJorN(i) = 0 ContarJorF(i) = 0 Next TabelaLc = Tabela.Cells(2, Columns.Count).End(xlToLeft).Column TabelaLr = Tabela.Cells(Rows.Count, 1).End(xlUp).Row Tabela.Cells(3, 2).Resize(TabelaLr, TabelaLc).ClearContents ApontarJorLr = ApontarJor.Cells(Rows.Count, 1).End(xlUp).Row ApontarJor.Cells(5, 1).Resize(ApontarJorLr, 10).ClearContents ApontarPreLr = ApontarPre.Cells(Rows.Count, 1).End(xlUp).Row ApontarPre.Cells(5, 1).Resize(ApontarPreLr, 10).ClearContents For j = 2 To TabelaLc Select Case Tabela.Cells(2, j) Case Is = "Jornadas >12h" TabJor = j Case Is = "Média de Pré" TabMed = j Case Is = "Total Pré" TabPre = j Case Is = "SBR" TabSbr = j Case Is = "PTR" TabPtr = j Case Is = "PAR" TabPar = j Case Is = "ESP" TabEsp = j End Select Next For i = 1 To Worksheets.Count Sheets(i).Visible = True Sheets(i).AutoFilterMode = False If Sheets(i).Name = "Base" Then Sheets(i).Cells.Delete Next i MesaLr = Mesa.Cells(Rows.Count, 1).End(xlUp).Row MesaLc = Mesa.Cells(1, Columns.Count).End(xlToLeft).Column Turnos(0) = "07:00 X 15:20" Turnos(1) = "15:00 X 23:20" Turnos(2) = "23:00 X 07:20" TurnoNum(0) = 3 TurnoNum(1) = 11 TurnoNum(2) = 19 TurnoNum(3) = 27 EscalaLr = Escala.Cells(Rows.Count, 1).End(xlUp).Row If Escala.Cells(Rows.Count, 2).End(xlUp).Row <> EscalaLr Then MsgBox "Há erro no dia da semana ou na data!" & vbCrLf & "Incerrando o processo", 0 + vbCritical, "Aviso" Exit Sub End If EscalaLc = Escala.Cells(1, Columns.Count).End(xlToLeft).Column If Escala.Cells(2, Columns.Count).End(xlToLeft).Column <> EscalaLc Or Escala.Cells(3, Columns.Count).End(xlToLeft).Column <> EscalaLc Then MsgBox "Há erro na Mesa ou Turno ou Nome " & vbCrLf & "Incerrando o processo", 0 + vbCritical, "Aviso" Exit Sub End If QtTec = Application.WorksheetFunction.CountA(Escala.Cells(1, 3).Resize(1, EscalaLc - 2)) QtSup = Application.WorksheetFunction.CountIf(Escala.Cells(1, 3).Resize(1, EscalaLc - 2), "Supervisor") QtTec = QtTec - QtSup ReDim NomeTec(QtTec - 1), NomeSup(QtSup - 1) As String ReDim ClmTec(QtTec - 1), ClmSup(QtSup - 1) As Byte 'i = 0 'For j = 2 To (QtSup + 2) 'If Escala.Cells(1, j) <> "" And Escala.Cells(3, j) <> "" Then 'NomeSup(i) = Escala.Cells(3, j) 'ClmSup(i) = j 'i = i + 1 'End If 'Next j 'i = 0 'For j = ((QtSup + 2) + 2) To EscalaLa 'If Escala.Cells(1, j) <> "" And Escala.Cells(3, j) <> "" Then 'NomeTec(i) = Escala.Cells(3, j) 'ClmTec(i) = j 'i = i + 1 'End If 'Next j i = 0 For j = 2 To EscalaLc If Escala.Cells(1, j) <> "" Then If Escala.Cells(1, j) <> Escala.Cells(1, j - 1) Then Select Case Escala.Cells(1, j) Case Is = "Supervisor" SupIni = j Case Else MesaIni(i) = j End Select Else If Escala.Cells(1, j) <> Escala.Cells(1, j + 1) Then Select Case Escala.Cells(1, j) Case Is = "Supervisor" SupFin = j Case Else MesaFin(i) = j i = i + 1 End Select End If End If End If Next j Dim ClmDestacamento As Byte, ClmTracao As Byte, ClmInicio As Byte, ClmCargo As Byte, ClmFuncao As Byte Dim ClmJornadaSegura As Byte, ClmApontamentoPre As Byte, ClmapontamentoJornada As Byte Dim ClmJor As Long, ClmPre As Long, ClmSbr As Byte, ClmPtr As Byte, ClmPar As Byte, ClmEsp As Byte Dim ClmGuerra As Byte, ClmMatricula As Byte Set Dados = Workbooks.Open("W:\CCO\6.Escala\8. Ponto de Maquinista\3. Hajime\10. Base\Dados para apresentação\20" & Ano & "\Dados de Apresentação_" & Mes & ".xlsx") DadosLc = Dados.Sheets("Base").Cells(1, Columns.Count).End(xlToLeft).Column For j = 1 To DadosLc Select Case Dados.Sheets("Base").Cells(1, j) Case Is = "Guerra" ClmGuerra = j Case Is = "Matrícula" ClmMatricula = j Case Is = "Cargo" ClmCargo = j Case Is = "Função" ClmFuncao = j Case Is = "Destacamento" ClmDestacamento = j Case Is = "Início" ClmInicio = j Case Is = "Jor.Sg" ClmJornadaSegura = j Case Is = "Pré(Pré-Pós_Oficial)" ClmPre = j Case Is = "Pré(SBR_Oficial)" ClmSbr = j Case Is = "Pré(PTR_Oficial)" ClmPtr = j Case Is = "Pré(PAR_Oficial)" ClmPar = j Exit For Case Is = "Pré(ESP_Oficial)" ClmEsp = j Case Is = "Pré+6" ClmApontamentoPre = j Case Is = "JorSeg+10" ClmapontamentoJornada = j End Select Next j Dados.Sheets("Base").Cells(1, 1).AutoFilter ClmJornadaSegura, ">0" Dados.Sheets("Base").Cells(1, 1).AutoFilter ClmPre, ">0" Dados.Sheets("base").Cells(1, 1).AutoFilter ClmCargo, "MAQ" Dados.Sheets("base").Cells(1, 1).AutoFilter ClmFuncao, Array("TRE", "FIXA", "HLP", "TSN"), Operator:=xlFilterValues Dados.Sheets("Base").Cells(1, 1).CurrentRegion.Copy Destination:=Base.Cells(1, 1) Dados.Close BaseLr = Base.Cells(Rows.Count, 1).End(xlUp).Row BaseLc = Base.Cells(1, Columns.Count).End(xlToLeft).Column For i = 2 To BaseLr If Base.Cells(i, ClmJornadaSegura) > 12 Then Select Case Application.VLookup(Base.Cells(i, ClmDestacamento), Mesa.Cells(1, 1).Resize(MesaLr, MesaLc), 2, 0) Case 0 To 6 m = Application.VLookup(Base.Cells(i, ClmDestacamento), Mesa.Cells(1, 1).Resize(MesaLr, MesaLc), 2, 0) If Mes = Month(Base.Cells(i, ClmapontamentoJornada)) Then If Hour(Base.Cells(i, ClmapontamentoJornada)) >= 6 Or Hour(Base.Cells(i, ClmapontamentoJornada)) = 23 Then Mais = 3 Linha = Day(Base.Cells(i, ClmapontamentoJornada)) + Mais Select Case Hour(Base.Cells(i, ClmapontamentoJornada)) Case 7 To 14 t = 0 Case 15 To 22 t = 1 Case Is = 23, 0 To 6 t = 2 End Select Else Mais = 2 Linha = Day(Base.Cells(i, ClmapontamentoJornada)) + Mais t = 2 End If End If ApontarJorLr = ApontarJor.Cells(Rows.Count, 1).End(xlUp).Row + 1 For s = SupIni To SupFin Debug.Print Escala.Cells(Linha, s) If Escala.Cells(Linha, s) = Turnos(t) Then If ApontarJor.Cells(ApontarJorLr, 9) = "" Then ApontarJor.Cells(ApontarJorLr, 9) = Escala.Cells(3, s) Else ApontarJor.Cells(ApontarJorLr, 10) = Escala.Cells(3, s) Exit For End If End If Next s For k = MesaIni(m) To MesaFin(m) If Escala.Cells(Linha, k) = Turnos(t) Then If ApontarJor.Cells(ApontarJorLr, 7) = "" Then If Escala.Cells(2, k) = "Manhã" Or Escala.Cells(2, k) = "Tarde" Or _ Escala.Cells(2, k) = "Noite" Or Escala.Cells(2, k) = "Folguista" Then ApontarJor.Cells(ApontarJorLr, 7) = Escala.Cells(3, k) ApontarJor.Cells(ApontarJorLr, 5) = Escala.Cells(2, k) If Escala.Cells(2, k) = "Folguista" Then MudarTurno = 3 Else ApontarJor.Cells(ApontarJorLr, 8) = Escala.Cells(3, k) End If Else If ApontarJor.Cells(ApontarJorLr, 8) = "" Then ApontarJor.Cells(ApontarJorLr, 8) = Escala.Cells(3, k) Exit For End If End If Next k ApontarJor.Cells(ApontarJorLr, 1) = Base.Cells(i, ClmDestacamento) ApontarJor.Cells(ApontarJorLr, 2) = Base.Cells(i, ClmGuerra) ApontarJor.Cells(ApontarJorLr, 3) = Base.Cells(i, ClmMatricula) ApontarJor.Cells(ApontarJorLr, 4) = Base.Cells(i, ClmapontamentoJornada) ApontarJor.Cells(ApontarJorLr, 6) = m If MudarTurno = 3 Then t = MudarTurno ContarJor(t) = ContarJor(t) + 1 Tabela.Cells(TurnoNum(t), TabJor) = ContarJor(t) Select Case t Case Is = 0 ContarJorM(m) = ContarJorM(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarJorM(m) Case Is = 1 ContarJorT(m) = ContarJorT(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarJorT(m) Case Is = 2 ContarJorN(m) = ContarJorN(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarJorN(m) Case Is = 3 ContarJorF(m) = ContarJorF(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarJorF(m) End Select End Select End If If Base.Cells(i, ClmApontamentoPre) > 6 Then Select Case Application.VLookup(Base.Cells(i, ClmDestacamento), Mesa.Cells(1, 1).Resize(MesaLr, MesaLc), 2, 0) Case 0 To 6 m = Application.VLookup(Base.Cells(i, ClmDestacamento), Mesa.Cells(1, 1).Resize(MesaLr, MesaLc), 2, 0) If Mes = Month(Base.Cells(i, ClmApontamentoPre)) Then If Hour(Base.Cells(i, ClmApontamentoPre)) >= 6 Or Hour(Base.Cells(i, ClmApontamentoPre)) = 23 Then Mais = 3 Linha = Day(Base.Cells(i, ClmApontamentoPre)) + 3 Select Case Hour(Base.Cells(i, ClmApontamentoPre)) Case 7 To 14 t = 0 Case 15 To 22 t = 1 Case Is = 23, 0 To 6 t = 2 End Select Else Mais = 2 Linha = Day(Base.Cells(i, ClmApontamentoPre)) + 2 t = 2 End If End If ApontarPreLr = ApontarPre.Cells(Rows.Count, 1).End(xlUp).Row + 1 For s = SupIni To SupFin If Escala.Cells(Linha, s) = Turnos(t) Then If ApontarPre.Cells(ApontarPreLr, 9) = "" Then ApontarPre.Cells(ApontarPreLr, 9) = Escala.Cells(3, s) Else ApontarPre.Cells(ApontarPreLr, 10) = Escala.Cells(3, s) Exit For End If End If Next s For k = MesaIni(m) To MesaFin(m) If Escala.Cells(Linha, k) = Turnos(t) Then If ApontarPre.Cells(ApontarPreLr, 7) = "" Then If Escala.Cells(2, k) = "Manhã" Or Escala.Cells(2, k) = "Tarde" Or _ Escala.Cells(2, k) = "Noite" Or Escala.Cells(2, k) = "Folguista" Then ApontarPre.Cells(ApontarPreLr, 7) = Escala.Cells(3, k) ApontarPre.Cells(ApontarPreLr, 5) = Escala.Cells(2, k) Else ApontarPre.Cells(ApontarPreLr, 8) = Escala.Cells(3, k) End If Else If ApontarPre.Cells(ApontarPreLr, 8) = "" Then ApontarPre.Cells(ApontarPreLr, 8) = Escala.Cells(3, k) Exit For End If End If Next k If ApontarPre.Cells(ApontarPreLr, 5) = "" Then MsgBox "ninguém escalado na data " & Linha - Mais & "/" & Mes & " no perído " & Turnos(t) End If ApontarPre.Cells(ApontarPreLr, 1) = Base.Cells(i, ClmDestacamento) ApontarPre.Cells(ApontarPreLr, 2) = Base.Cells(i, ClmGuerra) ApontarPre.Cells(ApontarPreLr, 3) = Base.Cells(i, ClmMatricula) ApontarPre.Cells(ApontarPreLr, 4) = Base.Cells(i, ClmapontamentoJornada) ApontarPre.Cells(ApontarPreLr, 6) = m ' Select Case t ' Case Is = 0 ' ApontarPre.Cells(ApontarPreLr, 5) = "Manhã" ' Case Is = 1 ' ApontarPre.Cells(ApontarPreLr, 5) = "Tarde" ' Case Is = 2 ' ApontarPre.Cells(ApontarPreLr, 5) = "Noite" ' End Select ' ' ' Select Case t ' Case Is = 0 ' ContarPreM(m) = ContarPreM(m) + 1 ' Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarPreM(m) ' Case Is = 1 ' ContarPreT(m) = ContarPreT(m) + 1 ' Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarPreT(m) ' Case Is = 2 ' ContarPreN(m) = ContarPreN(m) + 1 ' Tabela.Cells(TurnoNum(t) + m + 1, TabJor) = ContarPreT(m) ' End Select End Select End If Select Case Application.VLookup(Base.Cells(i, ClmDestacamento), Mesa.Cells(1, 1).Resize(MesaLr, MesaLc), 2, 0) Case 0 To 6 m = Application.VLookup(Base.Cells(i, ClmDestacamento), Mesa.Cells(1, 1).Resize(MesaLr, MesaLc), 2, 0) If Mes = Month(Base.Cells(i, ClmInicio)) Then If Hour(Base.Cells(i, ClmInicio)) >= 6 Or Hour(Base.Cells(i, ClmInicio)) = 23 Then Linha = Day(Base.Cells(i, ClmInicio)) + 3 Select Case Hour(Base.Cells(i, ClmInicio)) Case 7 To 14 t = 0 Case 15 To 22 t = 1 Case Is = 23 t = 2 End Select Else Linha = Day(Base.Cells(i, ClmInicio)) + 2 t = 2 End If End If For k = MesaIni(m) To MesaFin(m) If Escala.Cells(Linha, k) = Turnos(t) Then If Escala.Cells(2, k) = "Folguista" Then MudarTurno = 3 End If Next If MudarTurno = 3 Then t = MudarTurno ContarPre(t) = ContarPre(t) + 1 Select Case t Case Is = 0 ContarPreM(m) = ContarPreM(m) Case Is = 1 ContarPreT(m) = ContarPreT(m) Case Is = 2 ContarPreN(m) = ContarPreN(m) Case Is = 3 ContarPreF(m) = ContarPreF(m) End Select Tabela.Cells(TurnoNum(t), TabPre) = Tabela.Cells(TurnoNum(t), TabPre) + Base.Cells(i, ClmPre) Tabela.Cells(TurnoNum(t), TabMed) = Tabela.Cells(TurnoNum(t), TabPre) / ContarPre(t) Tabela.Cells(TurnoNum(t), TabSbr) = Tabela.Cells(TurnoNum(t), TabSbr) + Base.Cells(i, ClmSbr) Tabela.Cells(TurnoNum(t), TabPtr) = Tabela.Cells(TurnoNum(t), TabPtr) + Base.Cells(i, ClmPtr) Tabela.Cells(TurnoNum(t), TabPar) = Tabela.Cells(TurnoNum(t), TabPar) + Base.Cells(i, ClmPar) Tabela.Cells(TurnoNum(t), TabEsp) = Tabela.Cells(TurnoNum(t), TabEsp) + Base.Cells(i, ClmEsp) Tabela.Cells(TurnoNum(t) + m + 1, TabPre) = Tabela.Cells(TurnoNum(t) + m + 1, TabPre) + Base.Cells(i, ClmPre) Select Case t Case Is = 0 ContarPreM(m) = ContarPreM(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabMed) = Tabela.Cells(TurnoNum(t) + m + 1, TabPre) / ContarPreM(m) Case Is = 1 ContarPreT(m) = ContarPreT(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabMed) = Tabela.Cells(TurnoNum(t) + m + 1, TabPre) / ContarPreT(m) Case Is = 2 ContarPreN(m) = ContarPreN(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabMed) = Tabela.Cells(TurnoNum(t) + m + 1, TabPre) / ContarPreN(m) Case Is = 3 ContarPreF(m) = ContarPreF(m) + 1 Tabela.Cells(TurnoNum(t) + m + 1, TabMed) = Tabela.Cells(TurnoNum(t) + m + 1, TabPre) / ContarPreF(m) End Select Tabela.Cells(TurnoNum(t) + m + 1, TabSbr) = Tabela.Cells(TurnoNum(t) + m + 1, TabSbr) + Base.Cells(i, ClmSbr) Tabela.Cells(TurnoNum(t) + m + 1, TabPtr) = Tabela.Cells(TurnoNum(t) + m + 1, TabPtr) + Base.Cells(i, ClmPtr) Tabela.Cells(TurnoNum(t) + m + 1, TabPar) = Tabela.Cells(TurnoNum(t) + m + 1, TabPar) + Base.Cells(i, ClmPar) Tabela.Cells(TurnoNum(t) + m + 1, TabEsp) = Tabela.Cells(TurnoNum(t) + m + 1, TabEsp) + Base.Cells(i, ClmEsp) End Select Debug.Print i MudarTurno = 0 Next i For i = 1 To Worksheets.Count If Sheets(i).Name <> "Escala de Envio" And Sheets(i).Name <> "Tabela" And _ Sheets(i).Name <> "Apontamentos de Jor.Seg >12h" And Sheets(i).Name <> "Apontamentos de Pré >6h" Then Sheets(i).Visible = False Sheets(i).AutoFilterMode = False If Sheets(i).Name = "Base" Then Sheets(i).Cells.Delete Next i End Sub
  3. ola estou tentando solucionar um problema eu tenho duas tabelas cad_funcionario id nome departamento cargo 1 karla TI desenvolvimento 2 roberta RH cordenadora 3 lucas RH analista 4 joao fiscal analista 5 Carlos Ti DBA cad_salario id cargo salario 1 desenvolvimento 1000 2 cordenadora 5000 3 analista 3000 4 dba 4000 no problema esta pedindo para eu reajustar alguns salarios dependendo de seu cargo fiz isso por meio do case, porem depois pede para fazer um select que retorne nome, departamento, cargo, salario atual e salario reajustado, so que quando uso o select imprimi os campos repetidamente, no caso existem cargo e id em ambos, so queria que mostrace todos os campos da cad_funcionario e mostre na frente os campos salario e salario reajustado. segue o codigo que eu fiz ate agora select *, case when salario = 1000 then (salario*0.1) + salario when salario = 5000 then (salario*0.15) + salario when salario = 3000 then (salario*0.2) + salario when salario = 4000 then(salario*0.15)+salario end reajustado from cad_salario inner join cad_funcionario on cad_salario.cargo = cad_funcionario.cargo; gostaria que mi ajudem para não haver ambiguidade na hora de eu mostrar o resultado
  4. Bom dia, Segue um exemplo detalhado do problema, não consigo obter o total de registros para fazer a paginação. Quero entender porque o count com filtro 'venda' feito com having me retorna 3 linhas em vez de pegar o total. Desde já agradeço a ajuda! :) imovel ------------------------------------- id_imovel imovel publicado ----------- ---------- ------------ 1 imovel 01 1 2 imovel 02 1 3 imovel 03 1 4 imovel 04 1 imovel_custom ------------------------------------- imovel_id key value ----------- ---------- ---------- 1 transacao locacao 1 valor 10.0 1 area 120.0 2 transacao venda 2 valor 100.0 2 area 130.0 3 transacao venda 3 valor 110.0 3 area 140.0 4 transacao venda 4 valor 120.0 4 area 150.0 Lista com todos os tipos de transação: SELECT i.*, ic.*, MAX(CASE WHEN ic.key = 'transacao' THEN ic.value ELSE NULL END) AS transacao, MAX(CASE WHEN ic.key = 'valor' THEN ic.value ELSE NULL END) AS valor, MAX(CASE WHEN ic.key = 'area' THEN ic.value ELSE NULL END) AS area FROM imovel AS i LEFT JOIN imovel_custom AS ic ON i.id_imovel = ic.imovel_id WHERE publicado='1' GROUP BY i.id_imovel Resultado ------------------------------------------------------------------------- id_imovel imovel publicado transacao valor area ----------- ---------- ------------ ---------- ---------- ---------- 1 imovel 01 1 locacao 10.0 120.0 2 imovel 02 1 venda 100.0 130.0 3 imovel 03 1 venda 110.0 140.0 4 imovel 04 1 venda 120.0 150.0 Count para paginação com todos os tipos de transação: SELECT COUNT(DISTINCT i.id_imovel) as total FROM imovel AS i LEFT JOIN imovel_custom AS ic ON i.id_imovel = ic.imovel_id WHERE publicado='1' Resultado --------------------------------------------------------------- total --------- 4 Lista com transação venda: SELECT i.*, ic.*, MAX(CASE WHEN ic.key = 'transacao' THEN ic.value ELSE NULL END) AS transacao, MAX(CASE WHEN ic.key = 'valor' THEN ic.value ELSE NULL END) AS valor, MAX(CASE WHEN ic.key = 'area' THEN ic.value ELSE NULL END) AS area FROM imovel AS i LEFT JOIN imovel_custom AS ic ON i.id_imovel = ic.imovel_id WHERE publicado='1' GROUP BY i.id_imovel HAVING transacao='venda' Resultado ------------------------------------------------------------------------- id_imovel imovel publicado transacao valor area ----------- ---------- ------------ ---------- ---------- ---------- 2 imovel 02 1 venda 100.0 130.0 3 imovel 03 1 venda 110.0 140.0 4 imovel 04 1 venda 120.0 150.0 Count para paginação com transação venda: SELECT COUNT(DISTINCT i.id_imovel) as total FROM imovel AS i LEFT JOIN imovel_custom AS ic ON i.id_imovel = ic.imovel_id WHERE publicado='1' GROUP BY i.id_imovel HAVING ( MAX(CASE WHEN ic.key = 'transacao' THEN ic.value ELSE NULL END)='venda' ) Resultado --------------------------------------------------------------- total --------- 1 1 1
  5. vitaostm

    Query com case

    Olá pessoal, sou novo em programação e estou fazendo uma aplicação onde possuo a seguinte estrutura: | função | Registro | Nome Completo | | Operador | 156 | Fulano de Tal | A coluna função em meu formulário é digitada manualmente (titulo), a coluna registro é um droplist com todas as numerações vindas de uma tabela mysql, e o nome também vem da mesma tabela em uma textbox. 1. A droplist está funcionando, no entanto gostaria de usar um "case" ou de repetente outra função para ele listar somente os registros cuja coluna "função" da mesma tabela mostre "operador", como o exemplo que citei acima. 2. Ao selecionar o registro que ele desse um "load update" e carregasse o respectivo nome. Bom sei que é possível com AJAX, mas vamos por parte e resolvamos a questão 1. O que tenho é o seguinte: <?php header('Content-type: text/html; charset=utf-8'); $pdo = new PDO('mysql:host=localhost;dbname=banco', 'usuario', 'senha'); $sql = "SELECT registro FROM cadastro order by registro ASC"; $stmt = $pdo->prepare($sql); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); if ($stmt->rowCount() > 0) { ?> <select name="CMG"> <?php header('Content-type: text/html; charset=utf-8'); foreach ($results as $row) { ?> <option value="<?php header('Content-type: text/html; charset=utf-8'); echo $row['registro']; ?>"><?php echo $row['registro']; ?></option> <?php } ?> </select> <?php } ?> Desde já agradeço.
  6. Boa tarde, estou com um problema em meu sql, estou fazendo um relatório onde tenho que obter o valor da soma da venda de tickets de bilheteria de um cinema. tentei fazer um sum utilizando case e distinct mas infelizmente está acusando erro de sintaxe, por favor se alguém puder ajudar ficarei imensamente agradecido. segue o código abaixo. SELECT DATE_FORMAT(D.Data,'%d/%m/%Y') as Data, H.Horario, L.Linguagem, G.Genero, I.Indicacao, E.InteiraEspetaculo, P.EmpresaGrupo, P.Representante, E.Espetaculo, COUNT(DISTINCT(VI.ID)) AS QtdPublico, SUM(CASE WHEN DISTINCT(VI.ID) THEN VI.Total end) AS Total, <--- essa linha. SUM(DISTINCT(OC.Valor)) AS OutrosCustos FROM tblEspetaculo AS E INNER JOIN tblLinguagem as L ON L.ID = E.fk_IDLinguagem INNER JOIN tblIndicacao as I ON I.ID = E.fk_IDIndicacao INNER JOIN tblProdutor as P ON P.ID = E.fk_IDProdutor INNER JOIN tblGenero as G ON G.ID = E.fk_IDGenero INNER JOIN tblOutrosCustos as OC ON E.ID = OC.fk_IDEspetaculo INNER JOIN tblTaxas as T ON E.ID = T.fk_IDEspetaculo INNER JOIN tblData as D ON E.ID = D.fk_IDEspetaculo INNER JOIN tblHorario as H ON D.ID = H.fk_IDData INNER JOIN tblVendaIngresso as VI ON H.ID = VI.fk_IDHorario INNER JOIN tblIngresso as ING ON ING.ID = fk_IDIngresso WHERE DATE_FORMAT(VI.Data,"%Y") = "2015" GROUP BY E.ID, D.Data, H.Horario Obs: foi testado todo o sql sem aquela linha e funciona perfeitamente. Abraço.
  7. Visitante

    Ajuda com o Código

    Boa tarde, estou com problemas nesse código. O programa não passa para as perguntas de horários...o que me parece é que o switch case não reconhece a resposta anterior como verdadeira então não passa para a próxima etapa e repete. Mas já tentei de todo jeito e não consigo arrumar, Alguém pode me dar uma luz por favor ? #include <cstdio> #include <stdlib.h> #include <math.h> #include <conio.h> #include <iostream> #include <cstdlib> #include <stdio.h> int main() { //declaração de variáveis// char nome[40], curitiba[40], florianopolis[40], saobento[40], camboriu[40], matinhos[40], convencional[40], executivo [40]; int rg, codcontrole, viagem, horario, origem, destino, opcaobus, horarios; //espaço destinado para apresentação do programa// //variaveis recebendo dados// codcontrole = 1; //Laço de Retorno do { //Aqui o Programa pergunta a origem do passageiro printf("\nDe onde voce esta partindo? [1]curitiba, [2]florianopolis, [3]saobento, [4]camboriu ou [5]matinhos?\n"); scanf("%d", &origem); //Aqui o Programa pergunta o destino do passageiro printf("\nQual e seu destino? [1]curitiba, [2]florianopolis, [3]saobento, [4]camboriu ou [5]matinhos?\n"); scanf("%d", &destino); //Aqui o Programa pergunta o tipo de onibus printf("\nQual o tipo de onibus ? [1]Convencional ou [2]Executivo?\n"); scanf("%d", &opcaobus); if (origem == 1 && destino == 2 && opcaobus == 1) viagem = 1; else if (origem == 1 && destino == 2 && opcaobus == 2) viagem = 2; else if (origem == 1 && destino == 3 && opcaobus == 1) viagem = 3; else if (origem == 1 && destino == 3 && opcaobus == 2) viagem = 4; else if (origem == 1 && destino == 4 && opcaobus == 1) viagem = 5; else if (origem == 1 && destino == 4 && opcaobus == 2) viagem = 6; else if (origem == 1 && destino == 5 && opcaobus == 1) viagem = 7; else if (origem == 1 && destino == 5 && opcaobus == 2) viagem = 8; else if (origem == 2 && destino == 1 && opcaobus == 1) viagem = 9; else if (origem == 2 && destino == 1 && opcaobus == 2) viagem = 10; else if (origem == 2 && destino == 3 && opcaobus == 1) viagem = 11; else if (origem == 2 && destino == 3 && opcaobus == 2) viagem = 12; else if (origem == 2 && destino == 4 && opcaobus == 1) viagem = 13; else if (origem == 2 && destino == 4 && opcaobus == 2) viagem = 14; else if (origem == 2 && destino == 5 && opcaobus == 1) viagem = 15; else if (origem == 2 && destino == 5 && opcaobus == 2) viagem = 16; else if (origem == 3 && destino == 1 && opcaobus == 1) viagem = 17; else if (origem == 3 && destino == 1 && opcaobus == 2) viagem = 18; else if (origem == 3 && destino == 2 && opcaobus == 1) viagem = 19; else if (origem == 3 && destino == 2 && opcaobus == 2) viagem = 20; else if (origem == 3 && destino == 4 && opcaobus == 1) viagem = 21; else if (origem == 3 && destino == 4 && opcaobus == 2) viagem = 22; else if (origem == 3 && destino == 5 && opcaobus == 1) viagem = 23; else if (origem == 3 && destino == 5 && opcaobus == 2) viagem = 24; else if (origem == 4 && destino == 1 && opcaobus == 1) viagem = 25; else if (origem == 4 && destino == 1 && opcaobus == 2) viagem = 26; else if (origem == 4 && destino == 2 && opcaobus == 1) viagem = 27; else if (origem == 4 && destino == 2 && opcaobus == 2) viagem = 28; else if (origem == 4 && destino == 3 && opcaobus == 1) viagem = 29; else if (origem == 4 && destino == 3 && opcaobus == 2) viagem = 30; else if (origem == 4 && destino == 5 && opcaobus == 1) viagem = 31; else if (origem == 4 && destino == 5 && opcaobus == 2) viagem = 32; else if (origem == 5 && destino == 1 && opcaobus == 1) viagem = 33; else if (origem == 5 && destino == 1 && opcaobus == 2) viagem = 34; else if (origem == 5 && destino == 2 && opcaobus == 1) viagem = 35; else if (origem == 5 && destino == 2 && opcaobus == 2) viagem = 36; else if (origem == 5 && destino == 3 && opcaobus == 1) viagem = 37; else if (origem == 5 && destino == 3 && opcaobus == 2) viagem = 38; else if (origem == 5 && destino == 4 && opcaobus == 1) viagem = 39; else if (origem == 5 && destino == 4 && opcaobus == 2) viagem = 40; else printf("\nUma ou mais respostas são invalidas!\n"); //Aqui o Programa pergunta o horario da partida switch (horarios) { case 1: viagem = 1; printf("Digite 1 para 10:40 ou 2 para 17:00"); scanf("%d", &horario); break; case 2: viagem = 2; printf("Digite 1 para 11:00 ou 2 para 15:40"); scanf("%d", &horario); break; case 3: viagem = 3; printf("Digite 1 para 13:30 ou 2 para 09:30"); scanf("%d", &horario); break; case 4: viagem = 4; printf("Digite 1 para 12:00 ou 2 para 14:00"); scanf("%d", &horario); break; } //Aqui o Programa da o preço e pede os dados //Aqui o Programa Le os Dados do Cliente //Impressao da Passagem } while (codcontrole !=9999); }
  8. Estou com um probleminha basico na programação condicional. Eu coloquei o Switch (op) e um Case 'arroz'. Mas quando eu digito arroz quando eu executo, esta vindo a mensagem errada. Porem se eu colocar simbolos ou numeros o Case funciona. Obrigado pela ajuda.
  9. Como posso fazer no access a seguinte função do SQL? CASE WHEN DT.data_AAAAMMDD IN ('20150416','20150521','20150618','20150716','20150820','20150917','20151015','20151119','20151217') THEN 'DIA AÇÃO' ELSE 'DIA NORMAL' END OBRIGADA
  10. Não entendo porque o switch deste programa não está funcionando, quando escolho a opção entra no system ("pause"); #include <stdio.h> #include <stdlib.h> void menu(); void limpartela(); void sair(); void enter(); void denter(); void dentertabula(); void tabula(); void soma(); void subt(); void multi(); void divi(); char opc; int main() { menu(); system ("pause"); return 0; } void limpartela() { system("cls"); } void sair() { exit(1); } void enter() { printf("\n"); } void denter() { printf("\n\n"); } void dentertabula() { printf("\n\n\t"); } void tabula() { printf("\t"); } void menu() { limpartela(); int esc; printf("Que calculo voce quer fazer?"); dentertabula(); printf("1 - Soma"); enter(); tabula(); printf("2 - Subtracao"); enter(); tabula(); printf("3 - Multiplicacao"); enter(); tabula(); printf("4 - Divisao"); enter(); tabula(); printf("5 - Sair"); enter(); printf("Opcao: "); scanf("%d", &esc); getchar(); switch (esc) { case 1: void soma(); break; case 2: void subt(); break; case 3: void multi(); break; case 4: void divi(); break; case 5: void sair(); break; default: menu(); } } void soma(void) { limpartela(); int a, b, soma; printf("Digite os valores da soma:"); enter(); tabula(); printf("valor: "); scanf("%d", &a); tabula(); printf("+"); tabula(); printf("valor: "); scanf("%d", &b); soma = a + b; tabula(); printf("%d + %d = %d", a, b, soma); printf("\n\nResultado: %d", soma); printf("Resultado: %d", soma); printf("Deseja voltar ao menu? (s/n)"); scanf("%c", &opc); getchar(); if (opc=='s') { menu(); }else{ denter(); printf("Obrigado! "); } } void subt() { limpartela(); int c, d, sub; printf("Digite os valores da subtracao:"); enter(); tabula(); printf("valor: "); scanf("%d", &c); tabula(); printf("-"); tabula(); printf("valor: "); scanf("%d", &d); sub = c - d; tabula(); printf("%d - %d = %d", c, d, sub); printf("Resultado: %d", sub); printf("Deseja voltar ao menu? (s/n)"); scanf("%c", &opc); getchar(); if (opc=='s') { menu(); }else{ denter(); printf("Obrigado! "); } } void multi() { limpartela(); int e, f, mul; printf("Digite os valores da multiplicacao:"); enter(); tabula(); printf("valor: "); scanf("%d", &e); tabula(); printf("*"); tabula(); printf("valor: "); scanf("%d", &f); mul = e * f; tabula(); printf("%d * %d = %d", e, f, mul); printf("Resultado: %d", mul); printf("Deseja voltar ao menu? (s/n)"); scanf("%c", &opc); getchar(); if (opc=='s') { menu(); }else{ denter(); printf("Obrigado! "); } } void divi() { limpartela(); int g, h, div; printf("Digite os valores da divisao:"); enter(); tabula(); printf("valor: "); scanf("%d", &g); tabula(); printf("/"); tabula(); printf("valor: "); scanf("%d", &h); div = g / h; tabula(); printf("%d / %d = %d", g, h, div); printf("Resultado: %d", div); printf("Deseja voltar ao menu? (s/n)"); scanf("%c", &opc); getchar(); if (opc=='s') { menu(); }else{ denter(); printf("Obrigado! "); } }
  11. Eu gostaria de saber como resolver assim case 1: exemplo1; case 2: exemplo2; if (opcao == '0001'){ comando1; comando2; }else if(opcao == '0010'){ comando3; comando 4; } So que aconteceu assim, você digita 1, entra como "case 1", mostra resultado "exemplo1", certo, agora você digita 0001, entra como "case 1" de novo, so que eu não queria entrar de novo, quero entrar tipo como "opcao == 0001" e ai mostraria o resultado "comando1", so que não mostrou "comando 1" e mostrou "exemplo1", então como resolva isso? muito obrigado. por acaso, você tem como fazer os codigos C++ para estudar. Obrigado.
  12. Bom dia. Tenho um banco de dados Firebird 1.5.6. Estou rodando uma consulta muuuuuuuuito grande, cheia de subqueries somando varios valores. Basicamente o que eu preciso é agrupar pelo tipo de lançamento. Porem eu tenho 7 tipos de lancamentos diferentes, o que eu fiz foi transformar esses 7 tipos em 2 usando case, e agrupar por estes 2. vou postar parte do sql (n posso postar todo) pra vocês terem uma ideia do que to falando... select distinct fo.ano, fo.idlancamento, Case fo.tipolancamento when '3' then '1' else '0' end as tipofolha, fo.data, f.cliente, (select sum(fi.valor) from lanc fo3 inner join itemlanc fi on (fo3.folha=fi.folha) and (fo3.ano=fi.ano) inner join item e on (fi.item=e.item) where fi.item in (select es.itemsys from itemsys es where es.nome = 'valor1') and fo3.tipolancamento = fo.tipolancamento and fo3.data between '2013-01-01' and '2013-01-31' and fo3.cliente=f.cliente ) as valor_base, -- --contem varias subquereies como a anterior - - from lanc fo where fo.data between '2013-01-01' and '2013-01-31' and fo.ano=2013 group by case when fo.tipolancamento = 3 then 1 else 0 end o problema é que aquando rodo esse comando, aparece a seguinte msg: Error: GDS Exception. 335544569. Dynamic SQL Error SQL error code = -104 Invalid expression in the select list (not contained in either an aggregate function or the GROUP BY clause) SQLState: HY000 ErrorCode: 335544569 alguém sabe como me ajudar?
×
×
  • Criar Novo...