Combining two columns in a select won't work - ms-access

I need to combine values from 2 columns in a simple select statement using Access 2007 and ColdFusion 8. When I ran my query in Access I got the result without a problem, but when I put the query below in ColdFusion it won't run:
<cfquery name="Maj" datasource="#application.dsn#">
SELECT Majors & " " & GradeLevel
FROM Programs
WHERE Categories = 'Language'
ORDER BY Majors
</cfquery>
It produces the following error:
The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
The error occurred in C:\Inetpub\wwwroot\test.cfm: line 4
2 :
3 :
4 : <cfquery name="Maj" datasource="#application.dsn#">
5 : SELECT Majors & " " & GradeLevel
6 : FROM Programs

Use single instead of double quotes around the space you're adding between Majors and GradeLevel.
SELECT Majors & ' ' & GradeLevel
FROM Programs
WHERE Categories = 'Language'
ORDER BY Majors
If your next issue is how to alias that field expression, the Access db engine may object when you use an existing field name as the alias. Avoid that problem by choosing an alias which doesn't match any of the field names.
SELECT Majors & ' ' & GradeLevel AS Majors_GradeLevel

Related

MySqlException was unhandled on the adapter.Fill(table) when trying to add data to the datagrid

When my SQL query has a count function in the query it does not want to display the data in the DBGRID and I'm getting a "MySqlException was unhandled" error. As soon as I remove the count function it runs smoothly and displays the data on the DB grid.
Code below:
Dim cmd As New MySqlCommand("SELECT COUNT(a.client_id), a.CLIENT_ID,b.c_name, b.C_surname FROM tblinv_info a JOIN tblclientinfo b ON a.CLIENT_ID = b.CLIENT_ID WHERE extract(year from a.inv_date) in ('2018','2019') AND a.Client_id = b.Client_id GROUP BY a.client_id ORDER BY count(a.client_id) desc LIMIT 10", connection)
cmd.CommandTimeout = 500
Dim adapter As New MySqlDataAdapter(cmd)
Dim table As New DataTable()
adapter.Fill(table)
dbreport.DataSource = table
Any idea on why this could be happening? I'm running the program in Visual Studio coding with VB.NET and using a MySql database. The SQL command runs fine on the localhost database. Do I need to add data to the datagrid differently?
Error: Error code is as follows: An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Fatal error encountered attempting to read the resultset.
Two things jump out at me as being potentially wrong here:
You need to give your count column an alias
If you're running your MySQL in ONLY_FULL_GROUP_BY mode (you probably aren't, as you assert it works without the count, but you should), then you need to add b.c_name, b.C_surname to your GROUP BY or put them in aggregation functions (e.g. MAX(b.c_name) as c_name, MAX(b.C_surname) as c_surname) in your SELECT
On this latter point, if you don't group or aggregate and your MySQL is not in "only full groupby", then it will select values at random from the group, for c_name and c_surname, and this can lead to unexpected program effects
As a final point of advice, always avoid using functions on columns in the where clause. It would be better to say WHERE somedate >= '2018-01-01' AND somedate < 2020-01-01' than WHERE extract(YEAR from somedate) IN (2018,2019). If you use a function on a column value MySQL has to evaluate the function for every row, and it means indexes on the column cannot be used.

DATA_READ ERROR in hive+oracle join query in apache drill

I tried a join query in hive & oracle:
select x.net_profit, y.city from hive.testdb.`catalog_sales` x inner join oracle.USER.`customer_address` y on y.address_id = x.bill_add_id
Data types for these fields in Drill (I checked using describe table) :
address_id : Decimal
city : CHARACTER VARYING
bill_addr_id : Double
net_profit : Double
Above query worked & I got desired output.
I tried :
select y.city, sum(x.net_profit) from hive.testdb.`catalog_sales` x inner join oracle.USER.`customer_address` y on y.address_id = x.bill_addr_id group by y.city
I got the following Exception:
Error: DATA_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query.
sql SELECT "CA_CITY", CAST("ADDRESS_ID" AS DOUBLE) "$f13"
FROM "USER"."CUSTOMER_ADDRESS"
plugin oracle
Fragment 0:0
[Error Id: 7a2106da-1326-4de1-81e4-338a37acd7f9 on 192.168.145.151:31010] (state=,code=0)
Since joined columns(address_id,bill_addr_id) has different datatypes ie Decimal & Double but these are similar. So, I think this should be handled.
Is casting from Decimal to Double not possible? or is this a bug?

need to update the DB table through macros

I need to do the below update through macros,
If tbname = "PARTY" Then
Dim ssql As String
ssql = "Update PARTY Set PARTY_ID= (SELECT (max(PARTY_ID)+1) FROM PARTY) WHERE PARTY_ID ='DUMMY'
DB.Execute ssql, 64
End If
I am getting this error, while running the above statement.
Error Code: 1093. You can't specify target table 'PARTY' for update in
FROM clause 0.000 sec
Is there any other way to update the max(party_id)+1 to the row having party_id as "DUMMY"
The error you're having is in your SQL. You shouldn't be using a subselect here. The from-clause you're having is complete bull, because Update PARTY implies From PARTY
Additionally you seem to be calculating something strange, since you get an "invalid use of group function"-error. Short googling reveals this stackoverflow question, suggesting you should be using HAVING instead of WHERE
The fix is thusly simple:
ssql = "Update PARTY set PARTY_IT=(max(PARTY_ID) + 1) HAVING PARTY_ID='DUMMY'"

SQL query access pivot - error message 'field that has an invalid data type'

I'm running an SQL Query on MS Access.
the query looks like this:
TRANSFORM MIN(X_VALUE*MULTIPLE & ' ' & Y_VALUE)
SELECT A.ID
FROM ((MY_TABLE_A A
INNER JOIN MY_TABLE_B B ON B.ID = A.ID)
INNER JOIN MY_TABLE_C C ON C.FOO1_ID = A.FOO1_ID)
LEFT JOIN MY_TABLE_D D ON A.FOO2_ID = D.FOO2_ID
WHERE A.NUM ='FOO'
AND A.FOO_ID<>0
AND FOO3=1
GROUP BY A.ID PIVOT X_NAME IN('BLAH1', 'BLAH2')
when running this against local MDB file, it works.
when running this against Linked MDB (tables are linked to remote Oracle DB), I'm getting
ERROR [42000] [Microsoft][ODBC Microsoft Access Driver] The Microsoft
Access database engine could not execute the SQL statement because it
contains a field that has an invalid data type.
I've googled it, and couldn't find anything useful.
Any idea what can I do?
thanks.
The only statement in the query that even vaguely seems it would cause data type issues is the mixed types in the transform statement. Perhaps the following would work:
TRANSFORM MIN(CSTR(X_VALUE*MULTIPLE) & ' ' & CSTR(Y_VALUE))

Ambiguous column in where clause with qualified identifier

I get the following error:
ERROR 1052 (23000) at line 1: Column 'id' in where clause is ambiguous
Database: MySQL 5.5.30 (with all tables & columns in the schema)
SELECT cam.id, cam.name AS campaign_name, cam.subdomain, usr.id AS user_id, usr.email, usr.display_name AS user_display_name
FROM campaigns AS cam
INNER JOIN users AS usr
ON usr.id = cam.user_id
WHERE cam.state=2
AND (usr.email = "hello#me.com")
AND cam.id IN (105793,107290,106048,107107,15097,108580,107394,107560,108942,107670,107925,107056,106089,30931,106864,45868,107625,106878,106417,88858,106065,106758,3282,103372,4449,108440,107311,106239,105857,110712,110243,105939,107001,105950,107124,105882,106139,107548,432,107466,105942,107115,51342,106437,106482,107192,105867,106993,107667,103769,108745,49924,105763,105935,99140,107402,20637,21155,105788,89963,106421,70124,12304,4748,107015,109758,103145,107590,106968,110692,26533,24993,33660,107398,34584,49597,107518,108878,107036,107668,105410,107060,106135,29205,106026,79254,19132,108692,107572,106978,93445,105678,107386,105866,106449,112104,id,312012,308555,323625,314793,321195,310245,291101,306016,179787,308224,290484,318154,318116,70226,313982,311419,71197,320725,271482,317257,331048,316765,75626,76321,329973,314034,313681,313850,306487,317443,83760,314759,339990,323732,306470,330480,89979,304814,91365,92541,316037,315131,116866,315323,111116,316067,316164,197902,129172,319690,141828,313517,315838,317608,310268,315096,309004,290518,319317,316349,316365,336052,183055,321936,318115,316950,330521,331975,324045,315540,201025,315770,321558,317962,200887,317500,328721,320403,311716,315812,318661,344680,315843,317483,317588,258656,317936,329850,245554,344785,314865,316722,329550,314332,316360,291604,341029,261118,264395,335387,330797,315403,276508,275586,275717,281996,276689,276709,290611,276957,277804,278480,279042,279381,344612,317507,280753,329926,281838,304604,311660,287452,317401,292158,305459,287031,312338,330015,295562,343920,289372,289377,328036,313204,322422,289641,289457,289486,291896,289453,298416,316894,289474,289476,289491,289566,289586,289599,289672,289677,328909,293962,289720,289754,289745,289774,293484,330235,289898,303233,290083,290120,290242,290327,290359,290399,290438,290475,290555,290628,290872,291214,291418,291333,291652,291779,313939,292236,292340,314508,293046,293376,293185,342259,293263,293515,293600,294511,295262,293957,294073,317855,294397,311490,294691,298226,294861,295088,295145,302131,313369,296434,315662,310084,322252,297288,297360,297432,298203,298794,299262,333157,305860,304484,304422,304462,304649,327116,304487,304504,318641,304528,304574,312829,304617,304668,304632,304924,304658,318170,304651,304762,304771,304770,304806,305019,304831,305281,304892,304941,304990,305008,305040,305041,337272,305048,305107,305126,309925,305195,305256,305284,305334,305294,305327,305342,305405,305521,306679,305520,305546,305595,305650,305659,305732,305712,305779,305798,305819,305838,305873,319122,307946,305937,310949,306243,306112,306113,306120,306140,306142,322700,306197,307466,306263,313766,318790,306303,306344,306346,306374,306407,306406,306415,306445,306465,306486,306510,309524,341418,306687,309657,306759,308941,306751,306779,306756,306778,307202,308147,329657,330603,306859,320503,306849,306870,331402,306863,306928,306880,306894,306906,306918,306936,307479,306962,306970,306968,306982,306986,307001,307005,307008,309223,307007,307011,307061,307062,307092,308177,332228,307478,307127,328246,307161,337299,330104,307791,307412,307424,328480,307430,307447,307454,307473,307480,307512,307493,314340,307542,307526,307527,307545,307589,307623,336402,307652,307659,333206,307666,319975,307674,313887,310200,307713,307761,307771,309273,307817,307823,310259,307878,307889,312913,307976,308013,308021,308120,308174,308182,319795,308272,308290,333845,324412,308441,308450,308468,308479,308566,308525,308544,308561,308598,308616,308617,318255,308648,308651,308657,308663,308668,308671,335094,308680,311769,308872,334045,308717,308739,308788,308804,312547,308819,308827,308911,308904,309543,309015,309021,309052,309220,309079,309099,309163,309179,327520,309243,309236,314363,309263,309279,309285,309314,309364,309406,309457,309478,309495,309552,309952,309588,309613,309636,309638,309650,313116,310919,309734,314296,309811,309849,309882,325089,310459,338535,309931,309940,310023,310002,310007,310030,310032,318779,310081,310118,319304,310120,325833,310144,310145,310151,310204,310210,310278,329000,322690,310323,310383,317187,310442,310447,310451,310461,310488,311128,310545,310567,310566,310575,310597,310600,311042,310636,310661,310659,310666,310680,310707,310691,310709,310720,310722,310723,310725,314488,310736,310754,310762,310763,320101,310796,310894,310947,310953,312134,311039,311257,311200,311139,311152,311156,311164,311215,311218,311233,314467,311307,311313,311322,311333,311358,311379,311446,311448,315437,311530,311550,311570,311637,311638,311683,311702,311663,311699,311712,311739,311752,311808,311822,311826,342130,311881,311898,311907,325253,312032,312047,312050,312078,312098,313206,312165,312170,312188,312240,312241,312257,316515,312261,312302,312756,312340,312388,312459,322362,312453,312492,312501,312512,312568,312521,312543,314688,312584,312588,325194,312597,330651,312712,312821,312768,312809,325199,312857,312866,312871,312887,312891,312892,312906,312919,312928,312952,342782,312951,312968,312966,313020,313028,313057,313058,313062,313064,313071,327699,313471,313123,313193,324221,313270,313298,313300,313321,313354,313401,313408,314164,313479,344095,313554,314879,313582,313579,314849,313619,313620,313647,313674,313697,313715,313718,313721,313725,315051,313776,318773,313811,313857,333559,313843,313883,313920,313936,313974,320242,314247,315426,314032,314082,314085,314108,314112,314141,315142,314173,314229,314243,314664,314359,314365,314372,314400,314376,314395,314466,314468,314476,315731,314491,314492,316501,314875,314551,314562,314589,314614,314629,314651,314675,314652,314656,314751,315509,314770,314771,314834,314806,314860,314874,314916,315030,314923,314975,315021,315018,315019,315037,320761,337287,315047,315063,315139,315087,315102,315122,326907,315194,315200,315224,315232,315239,315252,315258,315318,315347,315357,315380,315388,338468,315395,315414,315420,316572,315441,335308,315453,315486,315488,317629,315565,315664,315686,315691,315707,315775,317867,315829,318320,315895,316394,315899,316178,315902,326518,316286,316030,316012,326614,316047,316062,316078,316128,316633,316151,316182,316189,319659,316822,316231,316238,316256,316267,321759,316282,317917,316372,316379,316402,316428,328069,316775,316457,316490,316467,316543,316586,316602,316616,316617,316646,320300,316685,316965,316739,328530,316790,316795,327353,316823,321203,316841,339982,330937,317245,316860,316881,316887,316892,316925,325234,342990,320909,331646,330988,320580,327576,317465,317054,323357,317149,317201,317239,317235,317243,319624,317355,317290,318297,317294,322359,320591,319131,317360,317410,317674,317533,317482,332117,317522,317556,317590,317613,317643,317673,319865,324529,317801,317866,323277,318733,317905,317909,318010,318056,318223,318146,318196,318208,318245,318262,318858,320332,322855,335628,321932,323584,325517,327285,326636,329112,327394,329130,328687,328625)
ORDER BY cam.id ASC
When I strip the "AND cam.id IN ()" part, it executes.
Why does this happen, although I have fully qualified the column (i.e. "cam.id" instead of "id")?
Things I tried:
removing the "AND cam.id" clause --> statement executes without error
using "campaigns.id" instead of "cam.id" --> error 1054 / "unknown column in where clause"
UPDATE it works, if I have only a few (say 5) items in the IN clause
I think that the root of the problem is in the following line:
AND cam.id IN (105793,107290,106048,107107,15097,108580,107394,107560,108942,107670,107925,107056,106089,30931,106864,45868,107625,106878,106417,88858,106065,106758,3282,103372,4449,108440,107311,106239,105857,110712,110243,105939,107001,105950,107124,105882,106139,107548,432,107466,105942,107115,51342,106437,106482,107192,105867,106993,107667,103769,108745,49924,105763,105935,99140,107402,20637,21155,105788,89963,106421,70124,12304,4748,107015,109758,103145,107590,106968,110692,26533,24993,33660,107398,34584,49597,107518,108878,107036,107668,105410,107060,106135,29205,106026,79254,19132,108692,107572,106978,93445,105678,107386,105866,106449,112104,id,312012,308555,323625,314793,321195,310245,291101,306016,179787,308224,290484,318154,318116,70226,313982,311419,71197,320725,271482,317257,331048,316765,75626,76321,329973,314034,313681,313850,306487,317443,83760,314759,339990,323732,306470,330480,89979,304814,91365,92541,316037,315131,116866,315323,111116,316067,316164,197902,129172,319690,141828,313517,315838,317608,310268,315096,309004,290518,319317,316349,316365,336052,183055,321936,318115,316950,330521,331975,324045,315540,201025,315770,321558,317962,200887,317500,328721,320403,311716,315812,318661,344680,315843,317483,317588,258656,317936,329850,245554,344785,314865,316722,329550,314332,316360,291604,341029,261118,264395,335387,330797,315403,276508,275586,275717,281996,276689,276709,290611,276957,277804,278480,279042,279381,344612,317507,280753,329926,281838,304604,311660,287452,317401,292158,305459,287031,312338,330015,295562,343920,289372,289377,328036,313204,322422,289641,289457,289486,291896,289453,298416,316894,289474,289476,289491,289566,289586,289599,289672,289677,328909,293962,289720,289754,289745,289774,293484,330235,289898,303233,290083,290120,290242,290327,290359,290399,290438,290475,290555,290628,290872,291214,291418,291333,291652,291779,313939,292236,292340,314508,293046,293376,293185,342259,293263,293515,293600,294511,295262,293957,294073,317855,294397,311490,294691,298226,294861,295088,295145,302131,313369,296434,315662,310084,322252,297288,297360,297432,298203,298794,299262,333157,305860,304484,304422,304462,304649,327116,304487,304504,318641,304528,304574,312829,304617,304668,304632,304924,304658,318170,304651,304762,304771,304770,304806,305019,304831,305281,304892,304941,304990,305008,305040,305041,337272,305048,305107,305126,309925,305195,305256,305284,305334,305294,305327,305342,305405,305521,306679,305520,305546,305595,305650,305659,305732,305712,305779,305798,305819,305838,305873,319122,307946,305937,310949,306243,306112,306113,306120,306140,306142,322700,306197,307466,306263,313766,318790,306303,306344,306346,306374,306407,306406,306415,306445,306465,306486,306510,309524,341418,306687,309657,306759,308941,306751,306779,306756,306778,307202,308147,329657,330603,306859,320503,306849,306870,331402,306863,306928,306880,306894,306906,306918,306936,307479,306962,306970,306968,306982,306986,307001,307005,307008,309223,307007,307011,307061,307062,307092,308177,332228,307478,307127,328246,307161,337299,330104,307791,307412,307424,328480,307430,307447,307454,307473,307480,307512,307493,314340,307542,307526,307527,307545,307589,307623,336402,307652,307659,333206,307666,319975,307674,313887,310200,307713,307761,307771,309273,307817,307823,310259,307878,307889,312913,307976,308013,308021,308120,308174,308182,319795,308272,308290,333845,324412,308441,308450,308468,308479,308566,308525,308544,308561,308598,308616,308617,318255,308648,308651,308657,308663,308668,308671,335094,308680,311769,308872,334045,308717,308739,308788,308804,312547,308819,308827,308911,308904,309543,309015,309021,309052,309220,309079,309099,309163,309179,327520,309243,309236,314363,309263,309279,309285,309314,309364,309406,309457,309478,309495,309552,309952,309588,309613,309636,309638,309650,313116,310919,309734,314296,309811,309849,309882,325089,310459,338535,309931,309940,310023,310002,310007,310030,310032,318779,310081,310118,319304,310120,325833,310144,310145,310151,310204,310210,310278,329000,322690,310323,310383,317187,310442,310447,310451,310461,310488,311128,310545,310567,310566,310575,310597,310600,311042,310636,310661,310659,310666,310680,310707,310691,310709,310720,310722,310723,310725,314488,310736,310754,310762,310763,320101,310796,310894,310947,310953,312134,311039,311257,311200,311139,311152,311156,311164,311215,311218,311233,314467,311307,311313,311322,311333,311358,311379,311446,311448,315437,311530,311550,311570,311637,311638,311683,311702,311663,311699,311712,311739,311752,311808,311822,311826,342130,311881,311898,311907,325253,312032,312047,312050,312078,312098,313206,312165,312170,312188,312240,312241,312257,316515,312261,312302,312756,312340,312388,312459,322362,312453,312492,312501,312512,312568,312521,312543,314688,312584,312588,325194,312597,330651,312712,312821,312768,312809,325199,312857,312866,312871,312887,312891,312892,312906,312919,312928,312952,342782,312951,312968,312966,313020,313028,313057,313058,313062,313064,313071,327699,313471,313123,313193,324221,313270,313298,313300,313321,313354,313401,313408,314164,313479,344095,313554,314879,313582,313579,314849,313619,313620,313647,313674,313697,313715,313718,313721,313725,315051,313776,318773,313811,313857,333559,313843,313883,313920,313936,313974,320242,314247,315426,314032,314082,314085,314108,314112,314141,315142,314173,314229,314243,314664,314359,314365,314372,314400,314376,314395,314466,314468,314476,315731,314491,314492,316501,314875,314551,314562,314589,314614,314629,314651,314675,314652,314656,314751,315509,314770,314771,314834,314806,314860,314874,314916,315030,314923,314975,315021,315018,315019,315037,320761,337287,315047,315063,315139,315087,315102,315122,326907,315194,315200,315224,315232,315239,315252,315258,315318,315347,315357,315380,315388,338468,315395,315414,315420,316572,315441,335308,315453,315486,315488,317629,315565,315664,315686,315691,315707,315775,317867,315829,318320,315895,316394,315899,316178,315902,326518,316286,316030,316012,326614,316047,316062,316078,316128,316633,316151,316182,316189,319659,316822,316231,316238,316256,316267,321759,316282,317917,316372,316379,316402,316428,328069,316775,316457,316490,316467,316543,316586,316602,316616,316617,316646,320300,316685,316965,316739,328530,316790,316795,327353,316823,321203,316841,339982,330937,317245,316860,316881,316887,316892,316925,325234,342990,320909,331646,330988,320580,327576,317465,317054,323357,317149,317201,317239,317235,317243,319624,317355,317290,318297,317294,322359,320591,319131,317360,317410,317674,317533,317482,332117,317522,317556,317590,317613,317643,317673,319865,324529,317801,317866,323277,318733,317905,317909,318010,318056,318223,318146,318196,318208,318245,318262,318858,320332,322855,335628,321932,323584,325517,327285,326636,329112,327394,329130,328687,328625)
if you'll look carefully you'll see that inside this huge list you accidentally entered "id" as one of the items.
your in list includes an identifier
...,112104,id,312012,...
^^-------------------- ???