I am trying to do something like this:
query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)
queryset += [(query, filename)]
df = pd.read_sql(query, engine.connect())
but I get this error:
SQLNumResultCols failed: [IBM][CLI Driver][IDS/UNIX64] A syntax error has occurred. SQLCODE=-201
I guess its becuase of the quotation marks but i'm not sure how to modify it.
I already tried without backslash too
[SQL: select mandant,posnr,systemdat,fk_kto_auf,fk_kto_not1,fk_kto_not2,fk_kto_empf,fk_kto_adr5,fk_kto_adr6,fk_kto_adr7,fk_kto_adr8,fk_kto_adr9,adr_auftraggeber,anzahl_kolli,volumen,gewicht,lieferbedingung,aufdat,ankdat,versandort,modus,ladehafen,loeschhafen,bereich,nrkreis_nr from eakopf_t where posnr[10,10] = " " , and posnr[1,2] not in ("99","RE","UB") and mandant <> 999;]
You have:
query = (
"select mandant,posnr,"
"lieferbedingung,nrkreis_nr"
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
"and mandant <> 999;"
)
There is no space separating nrkreis_nr from from, so the printed query would contain:
select mandant,posnr,lieferbedingung,nrkreis_nrfrom eakopf_t where …
It's probably best to put spaces at the start (or the end) of each continuation line:
query = (
"select mandant, posnr,"
" lieferbedingung, nrkreis_nr"
" from eakopf_t where posnr[10,10] = \" \" and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
" and mandant <> 999;"
)
It's not necessary when there is a punctuation character at the end of one line or the beginning of the next (so the comma at the end of the first line of the string means the space at the start of the next line is not mandatory), but it is safest.
I also removed a stray comma and space in:
"from eakopf_t where posnr[10,10] = \" \" , and posnr[1,2] not in (\"99\",\"RE\",\"UB\")"
Related
i keep getting this error GROUP_CONCAT(""""[*],a.montant, a.type_avance,a.date_avance,
a.remark SEPARATOR '') as Avance [42001-214] ,and after
i removed GROUP_CONCAT to test the code i got the error:
Column "" not found; SQL statement [42122-214]
here is my code:
SELECT i.n_dossier , concat(\"<html>\",i.nom_prenom,\"<br></html>\")
,concat(\"<html>\",i.vehicule,\"<br></html>\"),i.prime_totale ,"
+ " i.date_effet , i.date_echean ,GROUP_CONCAT(\"<html>\",a.montant,"
+ " a.type_avance,a.date_avance,a.remark SEPARATOR \"<br>\") as Avance ,i.reste ,i.GSM,"
+ "i.observation ,\"</html>\" FROM info_impayee i LEFT JOIN avance a ON i.n_dossier = "
+ " a.n_dossier GROUP by i.n_dossier,i.date_dossier,i.anuller having i.anuller = ' active '
You must repalce
GROUP_CONCAT("<html>",a.montant, a.type_avance,a.date_avance,a.remark SEPARATOR "<br>")
with
GROUP_CONCAT(CONCAT("<html>",a.montant, a.type_avance,a.date_avance,a.remark) SEPARATOR "<br>")
GROUP_CONCAT needs to have 1 column, as you see in the samle CONCAT will do that.
I don't why you use single quorted ' active 'and doou
I would like to clean a column Header of the table so that my column header that has a name like below:
[Space][Space][Space]First Name[Space][Space]
[Space]MaintActType[Space]
TECO date[Space]
FIN Date
ABC indicator
COGS
Created On
And my desired Column Header Name to be like below:
First Name
Main Act Type
TECO Date
FIN Date
ABC Indicator
COGS
Created On
my code is as below:
let
Source = Excel.Workbook(File.Contents("C:\RawData\sample.xlsx"), null, true),
#"sample_Sheet" = Source{[Item="sample",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"sample_Sheet", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(#"Promoted Headers", Text.Trim),
#"Split CapitalLetter" = Table.TransformColumnNames(#"Trim ColumnSpace", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")),
#"Remove DoubleSpace" = Table.TransformColumnNames(#"Split CapitalLetter", each Replacer.ReplaceText(_, " ", " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Remove DoubleSpace", Text.Proper),
#"Remove Space" = Table.TransformColumnNames(#"Capitalise FirstLetter", each Text.Remove(_, {" "})),
#"Separate ColumnName" = Table.TransformColumnNames(#"Remove Space", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " "))
in
#"Separate ColumnName"
However, i get the result as below. Which is not what i wanted as all the capital letter we combined together. How do i change the code so that i get the result as wanted? I would really appreciate your help, please.
First Name
Main Act Type
TECODate
FINDate
ABCIndicator
COGS
Created On
Alternatively, i changed the code to:
let
Source = Excel.Workbook(File.Contents("C:\RawData\sample.xlsx"), null, true),
#"sample_Sheet" = Source{[Item="sample",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"sample_Sheet", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(Input, Text.Trim),
#"Separate ColumnName" = Table.TransformColumnNames(#"Trim ColumnSpace", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Separate ColumnName", Text.Proper)
in
#"Capitalise FirstLetter"
Unfortunately it return the result like so:
First Name
Main Act Type
Teco Date
Fin Date
Abc Indicator
COGS
Created On
I have no idea how to play around the code anymore.
One way is to mark the existing spaces with something (I used "ZZZ") and restore them back to spaces at the end. Here's your code with a couple of tweaks. Thanks for your code. I was trying to do Text.Proper and your sample helped me!
let
Source = Input,
#"Replaced Value" = Table.ReplaceValue(Source,"[Space]"," ",Replacer.ReplaceText,{"Headers"}),
#"Transposed Table" = Table.Transpose(#"Replaced Value"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table", [PromoteAllScalars=true]),
#"Trim ColumnSpace" = Table.TransformColumnNames(#"Promoted Headers", Text.Trim),
#"Change space to ZZZ" = Table.TransformColumnNames(#"Trim ColumnSpace", each Replacer.ReplaceText(_, " ", " ZZZ ")),
#"Split CapitalLetter" = Table.TransformColumnNames(#"Change space to ZZZ", each Text.Combine(Splitter.SplitTextByPositions(Text.PositionOfAny(_, {"A".."Z"},2)) (_), " ")),
#"Capitalise FirstLetter" = Table.TransformColumnNames(#"Split CapitalLetter", Text.Proper),
#"Remove Space" = Table.TransformColumnNames(#"Capitalise FirstLetter", each Text.Remove(_, {" "})),
#"Separate ColumnName" = Table.TransformColumnNames(#"Remove Space", each Text.Combine(Splitter.SplitTextByCharacterTransition({"a".."z"}, {"A".."Z"}) (_), " ")),
#"Change ZZZ to space" = Table.TransformColumnNames(#"Separate ColumnName", each Replacer.ReplaceText(_, "ZZZ", " ")),
#"Remove DoubleSpace" = Table.TransformColumnNames(#"Change ZZZ to space", each Replacer.ReplaceText(_, " ", " "))
in
#"Remove DoubleSpace"
I have a SSRS report with sql query as below:
="select ar_sum.client_id as Customer_Code,"&
" ar_sum.bill_number as PRO_NO,"&
" ar_sum.company_id as ORG,"&
" tlorder.pick_up_by as Pick_Up_Date,"&
" ar_sum.aging_date as Bill_Date,"&
" ar_sum.aging_date as Invoice_Date,"&
Switch(
Parameters!CompName.Value = "355", " case when tlorder.pick_up_by is null then ar_sum.adj_amt else ar_sum.orig_amt end",
Parameters!CompName.Value = "301" or Parameters!CompName.Value = "354", " case when ((tlorder.pick_up_by is null) and (substr(ar_sum.bill_number,1,1) not in('1','2','3','4','5','6','7','8','9','0'))) then ar_sum.adj_amt else ar_sum.orig_amt end"
)&
" as Original_Amount,"&
" case when tlorder.pick_up_by is null then ar_sum.adj_amt else ar_sum.orig_amt end as Invoice_Amount,"&
" case when tlorder.pick_up_by is null then ar_sum.pay_amt else (ar_sum.pay_amt - ar_sum.adj_amt) end as Amount_paid,"&
" ar_sum.bal_amt as Amount_Open,"&
" ar_sum.currency_code as Currency_code"&
" from TMWIN.ar_sum ar_sum"&
" left join TMWIN.tlorder tlorder on ar_sum.detail_line_id = tlorder.detail_line_id"&
" where ar_sum.company_id = " & Parameters!CompID.Value &
" and (ar_sum.bal_amt > 0.01 or ar_sum.bal_amt < -0.01)"&
Switch(
Parameters!CompName.Value = "355", "",
Parameters!CompName.Value = "301", " and ar_sum.ar_control_acct in ('301-1052-000-00-8','301-1053-000-00-8','301-1053-500-00-0','301-1052-500-00-0')",
Parameters!CompName.Value = "354", " and ar_sum.ar_control_acct not in ('301-1052-000-00-8','301-1053-000-00-8','301-1053-500-00-0','301-1052-500-00-0', '301-1052-000-00-7' ,'301-1053-000-00-7')")
When I run it, I got below error:
An error has occurred during report processing. (rsProcessingAborted)
Query execution failed for dataset 'DataSet1'. (rsErrorExecutingCommand)
ERROR [42S22] [IBM][CLI Driver][DB2/NT64] SQL0206N "AS" is not valid in the context where it is used. SQLSTATE=42703
I have tried to remove the AS word but no luck. Actually I did not change anything in the query and it is working before. And all my other queries have the AS word too.
Please help me I could not find where is the error.
Thanks for the help!
EDITS:
I am not really good at SSRS report. I found above query from below:
My query starts like this:
SELECT
#MIN(?dateYear) AS ?dateYears)
(GROUP_CONCAT(DISTINCT ?dateYear ; separator = ", ") AS ?dateYears)
(CONCAT(GROUP_CONCAT(DISTINCT ?gameENLabel; separator = ", ") ,", ", GROUP_CONCAT(DISTINCT ?gameJALabel; separator = ", "), ", ", GROUP_CONCAT(DISTINCT ?hepburnLabel; separator = ", "), ", ", GROUP_CONCAT(DISTINCT ?gameZHLabel; separator = ", "), ", ", GROUP_CONCAT(DISTINCT ?pinyinLabel; separator = ", ")) as ?wookie)
(GROUP_CONCAT(DISTINCT ?dataLink ; separator = ", ") AS ?dataLinks)
#(?game AS ?dataPages)
(GROUP_CONCAT(DISTINCT ?wikiLink ; separator = ", ") AS ?wikiLinks)
(GROUP_CONCAT(DISTINCT ?wikiName ; separator = ", ") AS ?wikiNames)
WHERE {
...
}
It works, but when GROUP_CONCAT(DISTINCT ?gameJALabel; separator = ", ") returns an empty spring, the comma immediately following it is still rendered. Can the CONCAT command be supplied with a separator that only gets rendered if the preceding command returns something? Is there a better way to do all this that I don't know about? Thanks!
Dim sql As String = "SELECT DISTINCT LED.IDX As IDX, CORPCODE, UNITTYPECODE, UPPERFORMATIONCODE, FORMATIONCODE, LED.UNITCODE As UNITCODE,LED.STORECODE As STORECODE, LED.SECTIONNO As SECTIONNO, LED.PARTNO As PARTNO, "
sql &= " LED.BATCHNO As BATCHNO, UNITITEMCATEGORYCODE, LEDGERDATE, ENTITLEMENT, HOLDING, SURPLUS, SHORTAGE, COSTHOLDING, COSTENTITLEMENT, INITIALSTOCK, EMPLOYQTY, FIGHTQTY, ITEMAGE1, ITEMAGE2, ITEMAGE3,"
sql &= " ITEMAGE4, LED.BAH_BEREK, LED.JENIS_BEREK, JPTD_NO, LASTUPDATE, LED.ITEMTYPECODE As ITEMTYPECODE, LED.TOOLTYPECODE As TOOLTYPECODE, LED.PAKAIBHGCODE, LED.PAKAICODE, ITEMNIDX, LED.CREATEID As CREATEID, "
sql &= " LED.UPDATEID As UPDATEID, LED.CREATEDATE As CREATEDATE, LED.UPDATEDATE As UPDATEDATE, "
sql &= " USERID, RANKCODE, SERVICENO, USERNAME, DESIGNATIONCODE, PASSWORD, "
sql &= " 'OPER' AS GROUPCODE,5 AS ACESSID, 0 AS STATUS "
sql &= " FROM (LEDGER AS LED) "
sql &= " LEFT JOIN NUSER On NUSER.USERID = LED.UPDATEID WHERE (1=1) "
If condation <> "" Then
sql += condation
End If
sql &= " UNION SELECT DISTINCT LED.IDX As IDX, CORPCODE, UNITTYPECODE, UPPERFORMATIONCODE, FORMATIONCODE, LED.UNITCODE As UNITCODE, LED.STORECODE As STORECODE, LED.SECTIONNO As SECTIONNO, LED.PARTNO As PARTNO, "
sql &= " LED.BATCHNO As BATCHNO, UNITITEMCATEGORYCODE, LEDGERDATE, ENTITLEMENT, HOLDING, SURPLUS, SHORTAGE, COSTHOLDING, COSTENTITLEMENT, INITIALSTOCK, EMPLOYQTY, FIGHTQTY, ITEMAGE1, ITEMAGE2, ITEMAGE3,"
sql &= " ITEMAGE4, LED.BAH_BEREK, LED.JENIS_BEREK, JPTD_NO, LASTUPDATE, LED.ITEMTYPECODE As ITEMTYPECODE, LED.TOOLTYPECODE As TOOLTYPECODE, LED.PAKAIBHGCODE, LED.PAKAICODE, ITEMNIDX, LED.CREATEID As CREATEID, "
sql &= " LED.UPDATEID As UPDATEID, LED.CREATEDATE As CREATEDATE, LED.UPDATEDATE As UPDATEDATE,"
sql &= " ('' AS USERID), ('' AS RANKCODE),('' AS SERVICENO),('' AS USERNAME),('' AS DESIGNATIONCODE), ('' AS PASSWORD), 'OPER',5 , STATUS "
sql &= " FROM LEDGER_HISTORY LED WHERE (1=1) "
error is Syntax error (missing operator) in query expression '('' AS USERID)'.
Can anyone help me to solve this
The error is correct. The problem is the parentheses.
This syntax is not appropriate for SQL:
SELECT ('' AS USERID)
However, this is:
SELECT ('') AS USERID
Or just:
SELECT '' AS USERID
You have the same problem with FROM (LEDGER AS LED).