Forum Discussion

grupoipemig's avatar
grupoipemig
New Member
4 years ago

Error in Sql Server base

Good morning/evening/night people!

 

I created a relatory in Power BI using temporary tables in SQL Server query, and in the first moment, everything work normaly.

But when I tried create other base with temporary tables, I can see the preview without problems. But when I click in "Close and apply" the system execute the query and show a error mensage, like this:
 
"Incorrect syntax next to 'INTO' keyword. Incorrect syntax next to the 'with' keyword. If this statement is a regular table expression, an xmlnamespaces clause, or a change-tracking context clause, the preceding statement must end with a semicolon."
 
PS: I use the comand "with" to put the comand nolock in the query to don't block the data base of the system.
 
Can anyone help me with this problem?

2 Replies

  • vanessafvg's avatar
    vanessafvg
    Community Champion

    can you share your sql code?    dont think this is a problem of no lock 

    • grupoipemig's avatar
      grupoipemig
      New Member

      I tried again and work normaly, can be any local problem in Power BI? Because I tried in saved archive and in new archive and I had the error.

       

      I can't share the SQL code, but I maked other equal that I used before.

      The SQL code is like this:

       

      SELECT A.Date AS MonthYear,
      CASE WHEN SUBSTRING(A.Date, 0, 3) = '01' THEN '01 - Janeiro'
      WHEN SUBSTRING(A.Date, 0, 3) = '02' THEN '02 - Fevereiro'
      WHEN SUBSTRING(A.Date, 0, 3) = '03' THEN '03 - Março'
      WHEN SUBSTRING(A.Date, 0, 3) = '04' THEN '04 - Abril'
      WHEN SUBSTRING(A.Date, 0, 3) = '05' THEN '05 - Maio'
      WHEN SUBSTRING(A.Date, 0, 3) = '06' THEN '06 - Junho'
      WHEN SUBSTRING(A.Date, 0, 3) = '07' THEN '07 - Julho'
      WHEN SUBSTRING(A.Date, 0, 3) = '08' THEN '08 - Agosto'
      WHEN SUBSTRING(A.Date, 0, 3) = '09' THEN '09 - Setembro'
      WHEN SUBSTRING(A.Date, 0, 3) = '10' THEN '10 - Outubro'
      WHEN SUBSTRING(A.Date, 0, 3) = '11' THEN '11 - Novembro'
      ELSE '12 - Dezembro' END AS Periodo,
      B.NameFun AS Consultor,
      C.NameSup AS Supervisor,
      A.Meta AS MetaMes
      INTO #METAS
      FROM MetasFuncionarios A
      LEFT JOIN Funcionarios B ON (A.FuncionarioCod = B.FuncionarioCod)
      LEFT JOIN Equipes C WITH(NOLOCK) ON (B.EquipeCod = C.EquipeCod)
      WHERE B.FuncionarioStatus = 'A'
      AND A.Observacoes = 'Comissao'
      SELECT * FROM #METAS
      DROP TABLE #METAS

       

       

      PS: I think I found the error but I'm not sure, maybe the problem is selecting DirectQuery. When I select Import and place the SQL query it works normally.