"Invalid column name" error when turning a question into a model

When turning a question into a model, we regularly get a "Invalid column name" error as shown on the screenshot. This happens only to Category fields with custom mapping, but not to all of them. Changing the field type doesn't fix it though. The query seems to render fine in the preview or after saving metadata changes, but the error appears again after a reload. In order to aviod it, we have to unselect the column in the query definition.

Metabase version: 1.44.6
used database: SQL Server
Logs:

[4a45fb19-8e0f-4d09-a141-204d154c5b46] 2023-01-03T16:17:27+01:00 ERROR metabase.query-processor.middleware.catch-exceptions Error processing query: Invalid column name 'Buying status'.
{:database_id 2,
 :started_at #t "2023-01-03T15:17:25.307472Z[GMT]",
 :via
 [{:status :failed,
   :class clojure.lang.ExceptionInfo,
   :error "Error executing query: Invalid column name 'Buying status'.",
   :stacktrace
   ["--> driver.sql_jdbc.execute$execute_reducible_query$fn__55246.invoke(execute.clj:502)"
    "driver.sql_jdbc.execute$execute_reducible_query.invokeStatic(execute.clj:499)"
    "driver.sql_jdbc.execute$execute_reducible_query.invoke(execute.clj:486)"
    "driver.sql_jdbc.execute$execute_reducible_query.invokeStatic(execute.clj:494)"
    "driver.sql_jdbc.execute$execute_reducible_query.invoke(execute.clj:486)"
    "driver.sql_jdbc$fn__91711.invokeStatic(sql_jdbc.clj:54)"
    "driver.sql_jdbc$fn__91711.invoke(sql_jdbc.clj:52)"
    "query_processor.context$executef.invokeStatic(context.clj:59)"
    "query_processor.context$executef.invoke(context.clj:48)"
    "query_processor.context.default$default_runf.invokeStatic(default.clj:67)"
    "query_processor.context.default$default_runf.invoke(default.clj:65)"
    "query_processor.context$runf.invokeStatic(context.clj:45)"
    "query_processor.context$runf.invoke(context.clj:39)"
    "query_processor.reducible$identity_qp.invokeStatic(reducible.clj:12)"
    "query_processor.reducible$identity_qp.invoke(reducible.clj:9)"
    "query_processor.middleware.cache$maybe_return_cached_results$maybe_return_cached_results_STAR___52623.invoke(cache.clj:220)"
    "query_processor.middleware.permissions$check_query_permissions$fn__48144.invoke(permissions.clj:109)"
    "metabase_enterprise.advanced_permissions.query_processor.middleware.permissions$check_download_permissions$fn__85604.invoke(permissions.clj:124)"
    "metabase_enterprise.sandbox.query_processor.middleware.column_level_perms_check$maybe_apply_column_level_perms_check$fn__87408.invoke(column_level_perms_check.clj:30)"
    "query_processor.middleware.mbql_to_native$mbql__GT_native$fn__51568.invoke(mbql_to_native.clj:23)"
    "query_processor$fn__54099$combined_post_process__54104$combined_post_process_STAR___54105.invoke(query_processor.clj:212)"
    "query_processor$fn__54099$combined_pre_process__54100$combined_pre_process_STAR___54101.invoke(query_processor.clj:209)"
    "query_processor.middleware.resolve_database_and_driver$resolve_database_and_driver$fn__52544$fn__52549.invoke(resolve_database_and_driver.clj:35)"
    "driver$do_with_driver.invokeStatic(driver.clj:75)"
    "driver$do_with_driver.invoke(driver.clj:71)"
    "query_processor.middleware.resolve_database_and_driver$resolve_database_and_driver$fn__52544.invoke(resolve_database_and_driver.clj:34)"
    "query_processor.middleware.fetch_source_query$resolve_card_id_source_tables$fn__48579.invoke(fetch_source_query.clj:349)"
    "query_processor.middleware.store$initialize_store$fn__48767$fn__48768.invoke(store.clj:11)"
    "query_processor.store$do_with_store.invokeStatic(store.clj:44)"
    "query_processor.store$do_with_store.invoke(store.clj:38)"
    "query_processor.middleware.store$initialize_store$fn__48767.invoke(store.clj:10)"
    "query_processor.middleware.normalize_query$normalize$fn__52816.invoke(normalize_query.clj:22)"
    "metabase_enterprise.audit_app.query_processor.middleware.handle_audit_queries$handle_internal_queries$fn__59641.invoke(handle_audit_queries.clj:130)"
    "query_processor.middleware.constraints$add_default_userland_constraints$fn__49849.invoke(constraints.clj:53)"
    "query_processor.middleware.process_userland_query$process_userland_query$fn__52755.invoke(process_userland_query.clj:145)"
    "query_processor.middleware.catch_exceptions$catch_exceptions$fn__53127.invoke(catch_exceptions.clj:167)"
    "query_processor.reducible$async_qp$qp_STAR___44982$thunk__44984.invoke(reducible.clj:100)"
    "query_processor.reducible$async_qp$qp_STAR___44982.invoke(reducible.clj:106)"
    "query_processor.reducible$async_qp$qp_STAR___44982.invoke(reducible.clj:91)"
    "query_processor.reducible$sync_qp$qp_STAR___44993.doInvoke(reducible.clj:126)"
    "query_processor$process_userland_query.invokeStatic(query_processor.clj:331)"
    "query_processor$process_userland_query.doInvoke(query_processor.clj:327)"
    "query_processor$fn__54146$process_query_and_save_execution_BANG___54155$fn__54158.invoke(query_processor.clj:342)"
    "query_processor$fn__54146$process_query_and_save_execution_BANG___54155.invoke(query_processor.clj:335)"
    "query_processor$fn__54190$process_query_and_save_with_max_results_constraints_BANG___54199$fn__54202.invoke(query_processor.clj:354)"
    "query_processor$fn__54190$process_query_and_save_with_max_results_constraints_BANG___54199.invoke(query_processor.clj:347)"
    "api.dataset$run_query_async$fn__69621.invoke(dataset.clj:69)"
    "query_processor.streaming$streaming_response_STAR_$fn__40100$fn__40101.invoke(streaming.clj:162)"
    "query_processor.streaming$streaming_response_STAR_$fn__40100.invoke(streaming.clj:161)"
    "async.streaming_response$do_f_STAR_.invokeStatic(streaming_response.clj:65)"
    "async.streaming_response$do_f_STAR_.invoke(streaming_response.clj:63)"
    "async.streaming_response$do_f_async$task__19006.invoke(streaming_response.clj:84)"],
   :error_type :invalid-query,
   :ex-data
   {:sql
    "-- Metabase:: userID: 1 queryType: MBQL queryHash: 4a750eff938bb297de8ecf3d41b2ecaf4ad6ebec865801d401f4439c31003f1d\nSELECT TOP 2000 \"source\".\"idcompany\" AS \"idcompany\", \"source\".\"status\" AS \"status\", \"source\".\"createdtime\" AS \"createdtime\", \"source\".\"timestamp\" AS \"timestamp\", \"source\".\"name\" AS \"name\", \"source\".\"phone\" AS \"phone\", \"source\".\"telefax\" AS \"telefax\", \"source\".\"www\" AS \"www\", \"source\".\"postaladdress1\" AS \"postaladdress1\", \"source\".\"visitingaddress1\" AS \"visitingaddress1\", \"source\".\"postaladdress2\" AS \"postaladdress2\", \"source\".\"visitingaddress2\" AS \"visitingaddress2\", \"source\".\"postalzipcode\" AS \"postalzipcode\", \"source\".\"postalcity\" AS \"postalcity\", \"source\".\"visitingzipcode\" AS \"visitingzipcode\", \"source\".\"visitingcity\" AS \"visitingcity\", \"source\".\"country\" AS \"country\", \"source\".\"fullpostaladdress\" AS \"fullpostaladdress\", \"source\".\"fullvisitingaddress\" AS \"fullvisitingaddress\", \"source\".\"inactive\" AS \"inactive\", \"source\".\"registrationno\" AS \"registrationno\", \"source\".\"coworker\" AS \"coworker\", \"source\".\"buyingstatus\" AS \"buyingstatus\", \"source\".\"vismaid\" AS \"vismaid\", \"source\".\"visma_turnover_yearnow\" AS \"visma_turnover_yearnow\", \"source\".\"visma_turnover_lastyear\" AS \"visma_turnover_lastyear\", \"source\".\"industry\" AS \"industry\", \"source\".\"classification\" AS \"classification\", \"source\".\"parid\" AS \"parid\", \"source\".\"noofemployeescompany\" AS \"noofemployeescompany\", \"source\".\"municipality\" AS \"municipality\", \"source\".\"maintrade\" AS \"maintrade\", \"source\".\"unittype\" AS \"unittype\", \"source\".\"creditinfo_bisnode\" AS \"creditinfo_bisnode\", \"source\".\"noofemployeesunit\" AS \"noofemployeesunit\", \"source\".\"county\" AS \"county\", \"source\".\"sni\" AS \"sni\", \"source\".\"mothercompany\" AS \"mothercompany\", \"source\".\"latestupdate\" AS \"latestupdate\", \"source\".\"creditinfo\" AS \"creditinfo\", \"source\".\"istemplatecompany\" AS \"istemplatecompany\", \"source\".\"erp_id\" AS \"erp_id\", \"source\".\"erp_turnover_yearnow\" AS \"erp_turnover_yearnow\", \"source\".\"erp_turnover_lastyear\" AS \"erp_turnover_lastyear\", \"source\".\"lastcustomervisit\" AS \"lastcustomervisit\", \"source\".\"goalvisits\" AS \"goalvisits\", \"source\".\"noofvisits\" AS \"noofvisits\", \"source\".\"latestsaleshistory\" AS \"latestsaleshistory\", \"source\".\"mothercompanylime\" AS \"mothercompanylime\", \"source\".\"acd_id\" AS \"acd_id\", \"source\".\"acd_lastupdated\" AS \"acd_lastupdated\", \"source\".\"acd_unittype\" AS \"acd_unittype\", \"source\".\"acd_unitstatus\" AS \"acd_unitstatus\", \"source\".\"acd_email\" AS \"acd_email\", \"source\".\"acd_noofemployeesunit\" AS \"acd_noofemployeesunit\", \"source\".\"acd_maintradecode\" AS \"acd_maintradecode\", \"source\".\"acd_maintrade\" AS \"acd_maintrade\", \"source\".\"acd_legalname\" AS \"acd_legalname\", \"source\".\"acd_legalform\" AS \"acd_legalform\", \"source\".\"acd_vatno\" AS \"acd_vatno\", \"source\".\"acd_noofemployeescompany\" AS \"acd_noofemployeescompany\", \"source\".\"acd_turnover\" AS \"acd_turnover\", \"source\".\"acd_turnovercurrency\" AS \"acd_turnovercurrency\", \"source\".\"acd_groupname\" AS \"acd_groupname\", \"source\".\"credittemplaterating\" AS \"credittemplaterating\", \"source\".\"credittemplatelastupdate\" AS \"credittemplatelastupdate\", \"source\".\"potential\" AS \"potential\", \"source\".\"invoiceaddress1\" AS \"invoiceaddress1\", \"source\".\"invoiceaddress2\" AS \"invoiceaddress2\", \"source\".\"invoicezipcode\" AS \"invoicezipcode\", \"source\".\"invoicecity\" AS \"invoicecity\", \"source\".\"fullinvoiceaddress\" AS \"fullinvoiceaddress\", \"source\".\"emailinvoice\" AS \"emailinvoice\", \"source\".\"erp_turnover_lastyeartodate\" AS \"erp_turnover_lastyeartodate\", \"source\".\"erp_lastsynced\" AS \"erp_lastsynced\", \"source\".\"erp_ytdgrowth\" AS \"erp_ytdgrowth\", \"source\".\"erp_errormessage\" AS \"erp_errormessage\", \"source\".\"erp_firstsynced\" AS \"erp_firstsynced\", \"source\".\"erp_status\" AS \"erp_status\", \"source\".\"erp_salestrend\" AS \"erp_salestrend\", \"source\".\"acd_errormessage\" AS \"acd_errormessage\", \"source\".\"coworker__via__coworker__firstname\" AS \"coworker__via__coworker__firstname\", \"source\".\"company__via__mothercompanylime__name\" AS \"company__via__mothercompanylime__name\", \"source\".\"Buying status\" AS \"Buying status\", \"source\".\"Industry\" AS \"Industry_2\", \"source\".\"Classification\" AS \"Classification_2\", \"source\".\"Is templatecompany\" AS \"Is templatecompany\", \"source\".\"Number of employees unit\" AS \"Number of employees unit\", \"source\".\"Number of employees company\" AS \"Number of employees company\", \"source\".\"Credit rating\" AS \"Credit rating\", \"source\".\"Potential\" AS \"Potential_2\", \"source\".\"Status ERP integration\" AS \"Status ERP integration\", \"source\".\"Sales trend\" AS \"Sales trend\" FROM (SELECT \"dbo\".\"company\".\"idcompany\" AS \"idcompany\", \"dbo\".\"company\".\"status\" AS \"status\", \"dbo\".\"company\".\"createdtime\" AS \"createdtime\", \"dbo\".\"company\".\"timestamp\" AS \"timestamp\", \"dbo\".\"company\".\"name\" AS \"name\", \"dbo\".\"company\".\"phone\" AS \"phone\", \"dbo\".\"company\".\"telefax\" AS \"telefax\", \"dbo\".\"company\".\"www\" AS \"www\", \"dbo\".\"company\".\"postaladdress1\" AS \"postaladdress1\", \"dbo\".\"company\".\"visitingaddress1\" AS \"visitingaddress1\", \"dbo\".\"company\".\"postaladdress2\" AS \"postaladdress2\", \"dbo\".\"company\".\"visitingaddress2\" AS \"visitingaddress2\", \"dbo\".\"company\".\"postalzipcode\" AS \"postalzipcode\", \"dbo\".\"company\".\"postalcity\" AS \"postalcity\", \"dbo\".\"company\".\"visitingzipcode\" AS \"visitingzipcode\", \"dbo\".\"company\".\"visitingcity\" AS \"visitingcity\", \"dbo\".\"company\".\"country\" AS \"country\", \"dbo\".\"company\".\"fullpostaladdress\" AS \"fullpostaladdress\", \"dbo\".\"company\".\"fullvisitingaddress\" AS \"fullvisitingaddress\", \"dbo\".\"company\".\"inactive\" AS \"inactive\", \"dbo\".\"company\".\"registrationno\" AS \"registrationno\", \"dbo\".\"company\".\"coworker\" AS \"coworker\", \"dbo\".\"company\".\"buyingstatus\" AS \"buyingstatus\", \"dbo\".\"company\".\"vismaid\" AS \"vismaid\", \"dbo\".\"company\".\"visma_turnover_yearnow\" AS \"visma_turnover_yearnow\", \"dbo\".\"company\".\"visma_turnover_lastyear\" AS \"visma_turnover_lastyear\", \"dbo\".\"company\".\"industry\" AS \"industry\", \"dbo\".\"company\".\"classification\" AS \"classification\", \"dbo\".\"company\".\"parid\" AS \"parid\", \"dbo\".\"company\".\"noofemployeescompany\" AS \"noofemployeescompany\", \"dbo\".\"company\".\"municipality\" AS \"municipality\", \"dbo\".\"company\".\"maintrade\" AS \"maintrade\", \"dbo\".\"company\".\"unittype\" AS \"unittype\", \"dbo\".\"company\".\"creditinfo_bisnode\" AS \"creditinfo_bisnode\", \"dbo\".\"company\".\"noofemployeesunit\" AS \"noofemployeesunit\", \"dbo\".\"company\".\"county\" AS \"county\", \"dbo\".\"company\".\"sni\" AS \"sni\", \"dbo\".\"company\".\"mothercompany\" AS \"mothercompany\", \"dbo\".\"company\".\"latestupdate\" AS \"latestupdate\", \"dbo\".\"company\".\"creditinfo\" AS \"creditinfo\", \"dbo\".\"company\".\"istemplatecompany\" AS \"istemplatecompany\", \"dbo\".\"company\".\"erp_id\" AS \"erp_id\", \"dbo\".\"company\".\"erp_turnover_yearnow\" AS \"erp_turnover_yearnow\", \"dbo\".\"company\".\"erp_turnover_lastyear\" AS \"erp_turnover_lastyear\", \"dbo\".\"company\".\"lastcustomervisit\" AS \"lastcustomervisit\", \"dbo\".\"company\".\"goalvisits\" AS \"goalvisits\", \"dbo\".\"company\".\"noofvisits\" AS \"noofvisits\", \"dbo\".\"company\".\"latestsaleshistory\" AS \"latestsaleshistory\", \"dbo\".\"company\".\"mothercompanylime\" AS \"mothercompanylime\", \"dbo\".\"company\".\"acd_id\" AS \"acd_id\", \"dbo\".\"company\".\"acd_lastupdated\" AS \"acd_lastupdated\", \"dbo\".\"company\".\"acd_unittype\" AS \"acd_unittype\", \"dbo\".\"company\".\"acd_unitstatus\" AS \"acd_unitstatus\", \"dbo\".\"company\".\"acd_email\" AS \"acd_email\", \"dbo\".\"company\".\"acd_noofemployeesunit\" AS \"acd_noofemployeesunit\", \"dbo\".\"company\".\"acd_maintradecode\" AS \"acd_maintradecode\", \"dbo\".\"company\".\"acd_maintrade\" AS \"acd_maintrade\", \"dbo\".\"company\".\"acd_legalname\" AS \"acd_legalname\", \"dbo\".\"company\".\"acd_legalform\" AS \"acd_legalform\", \"dbo\".\"company\".\"acd_vatno\" AS \"acd_vatno\", \"dbo\".\"company\".\"acd_noofemployeescompany\" AS \"acd_noofemployeescompany\", \"dbo\".\"company\".\"acd_turnover\" AS \"acd_turnover\", \"dbo\".\"company\".\"acd_turnovercurrency\" AS \"acd_turnovercurrency\", \"dbo\".\"company\".\"acd_groupname\" AS \"acd_groupname\", \"dbo\".\"company\".\"credittemplaterating\" AS \"credittemplaterating\", \"dbo\".\"company\".\"credittemplatelastupdate\" AS \"credittemplatelastupdate\", \"dbo\".\"company\".\"potential\" AS \"potential\", \"dbo\".\"company\".\"invoiceaddress1\" AS \"invoiceaddress1\", \"dbo\".\"company\".\"invoiceaddress2\" AS \"invoiceaddress2\", \"dbo\".\"company\".\"invoicezipcode\" AS \"invoicezipcode\", \"dbo\".\"company\".\"invoicecity\" AS \"invoicecity\", \"dbo\".\"company\".\"fullinvoiceaddress\" AS \"fullinvoiceaddress\", \"dbo\".\"company\".\"emailinvoice\" AS \"emailinvoice\", \"dbo\".\"company\".\"erp_turnover_lastyeartodate\" AS \"erp_turnover_lastyeartodate\", \"dbo\".\"company\".\"erp_lastsynced\" AS \"erp_lastsynced\", \"dbo\".\"company\".\"erp_ytdgrowth\" AS \"erp_ytdgrowth\", \"dbo\".\"company\".\"erp_errormessage\" AS \"erp_errormessage\", \"dbo\".\"company\".\"erp_firstsynced\" AS \"erp_firstsynced\", \"dbo\".\"company\".\"erp_status\" AS \"erp_status\", \"dbo\".\"company\".\"erp_salestrend\" AS \"erp_salestrend\", \"dbo\".\"company\".\"acd_errormessage\" AS \"acd_errormessage\", \"coworker__via__coworker\".\"firstname\" AS \"coworker__via__coworker__firstname\", \"company__via__mothercompanylime\".\"name\" AS \"company__via__mothercompanylime__name\" FROM \"dbo\".\"company\" LEFT JOIN \"dbo\".\"coworker\" \"coworker__via__coworker\" ON \"dbo\".\"company\".\"coworker\" = \"coworker__via__coworker\".\"idcoworker\" LEFT JOIN \"dbo\".\"company\" \"company__via__mothercompanylime\" ON \"dbo\".\"company\".\"mothercompanylime\" = \"company__via__mothercompanylime\".\"idcompany\" WHERE (\"dbo\".\"company\".\"status\" = 0 AND \"dbo\".\"company\".\"buyingstatus\" = 108601)) \"source\" ",
    :params nil,
    :type :invalid-query}}],
 :state "S0001",
 :error_type :invalid-query,
 :json_query
 {:type "query",
  :database 2,
  :query {:source-table "card__11"},
  :parameters [],
  :middleware {:js-int-to-string? true, :add-default-userland-constraints? true}},
 :native
 {:query
  "SELECT TOP 1048575 \"source\".\"idcompany\" AS \"idcompany\", \"source\".\"status\" AS \"status\", \"source\".\"createdtime\" AS \"createdtime\", \"source\".\"timestamp\" AS \"timestamp\", \"source\".\"name\" AS \"name\", \"source\".\"phone\" AS \"phone\", \"source\".\"telefax\" AS \"telefax\", \"source\".\"www\" AS \"www\", \"source\".\"postaladdress1\" AS \"postaladdress1\", \"source\".\"visitingaddress1\" AS \"visitingaddress1\", \"source\".\"postaladdress2\" AS \"postaladdress2\", \"source\".\"visitingaddress2\" AS \"visitingaddress2\", \"source\".\"postalzipcode\" AS \"postalzipcode\", \"source\".\"postalcity\" AS \"postalcity\", \"source\".\"visitingzipcode\" AS \"visitingzipcode\", \"source\".\"visitingcity\" AS \"visitingcity\", \"source\".\"country\" AS \"country\", \"source\".\"fullpostaladdress\" AS \"fullpostaladdress\", \"source\".\"fullvisitingaddress\" AS \"fullvisitingaddress\", \"source\".\"inactive\" AS \"inactive\", \"source\".\"registrationno\" AS \"registrationno\", \"source\".\"coworker\" AS \"coworker\", \"source\".\"buyingstatus\" AS \"buyingstatus\", \"source\".\"vismaid\" AS \"vismaid\", \"source\".\"visma_turnover_yearnow\" AS \"visma_turnover_yearnow\", \"source\".\"visma_turnover_lastyear\" AS \"visma_turnover_lastyear\", \"source\".\"industry\" AS \"industry\", \"source\".\"classification\" AS \"classification\", \"source\".\"parid\" AS \"parid\", \"source\".\"noofemployeescompany\" AS \"noofemployeescompany\", \"source\".\"municipality\" AS \"municipality\", \"source\".\"maintrade\" AS \"maintrade\", \"source\".\"unittype\" AS \"unittype\", \"source\".\"creditinfo_bisnode\" AS \"creditinfo_bisnode\", \"source\".\"noofemployeesunit\" AS \"noofemployeesunit\", \"source\".\"county\" AS \"county\", \"source\".\"sni\" AS \"sni\", \"source\".\"mothercompany\" AS \"mothercompany\", \"source\".\"latestupdate\" AS \"latestupdate\", \"source\".\"creditinfo\" AS \"creditinfo\", \"source\".\"istemplatecompany\" AS \"istemplatecompany\", \"source\".\"erp_id\" AS \"erp_id\", \"source\".\"erp_turnover_yearnow\" AS \"erp_turnover_yearnow\", \"source\".\"erp_turnover_lastyear\" AS \"erp_turnover_lastyear\", \"source\".\"lastcustomervisit\" AS \"lastcustomervisit\", \"source\".\"goalvisits\" AS \"goalvisits\", \"source\".\"noofvisits\" AS \"noofvisits\", \"source\".\"latestsaleshistory\" AS \"latestsaleshistory\", \"source\".\"mothercompanylime\" AS \"mothercompanylime\", \"source\".\"acd_id\" AS \"acd_id\", \"source\".\"acd_lastupdated\" AS \"acd_lastupdated\", \"source\".\"acd_unittype\" AS \"acd_unittype\", \"source\".\"acd_unitstatus\" AS \"acd_unitstatus\", \"source\".\"acd_email\" AS \"acd_email\", \"source\".\"acd_noofemployeesunit\" AS \"acd_noofemployeesunit\", \"source\".\"acd_maintradecode\" AS \"acd_maintradecode\", \"source\".\"acd_maintrade\" AS \"acd_maintrade\", \"source\".\"acd_legalname\" AS \"acd_legalname\", \"source\".\"acd_legalform\" AS \"acd_legalform\", \"source\".\"acd_vatno\" AS \"acd_vatno\", \"source\".\"acd_noofemployeescompany\" AS \"acd_noofemployeescompany\", \"source\".\"acd_turnover\" AS \"acd_turnover\", \"source\".\"acd_turnovercurrency\" AS \"acd_turnovercurrency\", \"source\".\"acd_groupname\" AS \"acd_groupname\", \"source\".\"credittemplaterating\" AS \"credittemplaterating\", \"source\".\"credittemplatelastupdate\" AS \"credittemplatelastupdate\", \"source\".\"potential\" AS \"potential\", \"source\".\"invoiceaddress1\" AS \"invoiceaddress1\", \"source\".\"invoiceaddress2\" AS \"invoiceaddress2\", \"source\".\"invoicezipcode\" AS \"invoicezipcode\", \"source\".\"invoicecity\" AS \"invoicecity\", \"source\".\"fullinvoiceaddress\" AS \"fullinvoiceaddress\", \"source\".\"emailinvoice\" AS \"emailinvoice\", \"source\".\"erp_turnover_lastyeartodate\" AS \"erp_turnover_lastyeartodate\", \"source\".\"erp_lastsynced\" AS \"erp_lastsynced\", \"source\".\"erp_ytdgrowth\" AS \"erp_ytdgrowth\", \"source\".\"erp_errormessage\" AS \"erp_errormessage\", \"source\".\"erp_firstsynced\" AS \"erp_firstsynced\", \"source\".\"erp_status\" AS \"erp_status\", \"source\".\"erp_salestrend\" AS \"erp_salestrend\", \"source\".\"acd_errormessage\" AS \"acd_errormessage\", \"source\".\"coworker__via__coworker__firstname\" AS \"coworker__via__coworker__firstname\", \"source\".\"company__via__mothercompanylime__name\" AS \"company__via__mothercompanylime__name\", \"source\".\"Buying status\" AS \"Buying status\", \"source\".\"Industry\" AS \"Industry_2\", \"source\".\"Classification\" AS \"Classification_2\", \"source\".\"Is templatecompany\" AS \"Is templatecompany\", \"source\".\"Number of employees unit\" AS \"Number of employees unit\", \"source\".\"Number of employees company\" AS \"Number of employees company\", \"source\".\"Credit rating\" AS \"Credit rating\", \"source\".\"Potential\" AS \"Potential_2\", \"source\".\"Status ERP integration\" AS \"Status ERP integration\", \"source\".\"Sales trend\" AS \"Sales trend\" FROM (SELECT \"dbo\".\"company\".\"idcompany\" AS \"idcompany\", \"dbo\".\"company\".\"status\" AS \"status\", \"dbo\".\"company\".\"createdtime\" AS \"createdtime\", \"dbo\".\"company\".\"timestamp\" AS \"timestamp\", \"dbo\".\"company\".\"name\" AS \"name\", \"dbo\".\"company\".\"phone\" AS \"phone\", \"dbo\".\"company\".\"telefax\" AS \"telefax\", \"dbo\".\"company\".\"www\" AS \"www\", \"dbo\".\"company\".\"postaladdress1\" AS \"postaladdress1\", \"dbo\".\"company\".\"visitingaddress1\" AS \"visitingaddress1\", \"dbo\".\"company\".\"postaladdress2\" AS \"postaladdress2\", \"dbo\".\"company\".\"visitingaddress2\" AS \"visitingaddress2\", \"dbo\".\"company\".\"postalzipcode\" AS \"postalzipcode\", \"dbo\".\"company\".\"postalcity\" AS \"postalcity\", \"dbo\".\"company\".\"visitingzipcode\" AS \"visitingzipcode\", \"dbo\".\"company\".\"visitingcity\" AS \"visitingcity\", \"dbo\".\"company\".\"country\" AS \"country\", \"dbo\".\"company\".\"fullpostaladdress\" AS \"fullpostaladdress\", \"dbo\".\"company\".\"fullvisitingaddress\" AS \"fullvisitingaddress\", \"dbo\".\"company\".\"inactive\" AS \"inactive\", \"dbo\".\"company\".\"registrationno\" AS \"registrationno\", \"dbo\".\"company\".\"coworker\" AS \"coworker\", \"dbo\".\"company\".\"buyingstatus\" AS \"buyingstatus\", \"dbo\".\"company\".\"vismaid\" AS \"vismaid\", \"dbo\".\"company\".\"visma_turnover_yearnow\" AS \"visma_turnover_yearnow\", \"dbo\".\"company\".\"visma_turnover_lastyear\" AS \"visma_turnover_lastyear\", \"dbo\".\"company\".\"industry\" AS \"industry\", \"dbo\".\"company\".\"classification\" AS \"classification\", \"dbo\".\"company\".\"parid\" AS \"parid\", \"dbo\".\"company\".\"noofemployeescompany\" AS \"noofemployeescompany\", \"dbo\".\"company\".\"municipality\" AS \"municipality\", \"dbo\".\"company\".\"maintrade\" AS \"maintrade\", \"dbo\".\"company\".\"unittype\" AS \"unittype\", \"dbo\".\"company\".\"creditinfo_bisnode\" AS \"creditinfo_bisnode\", \"dbo\".\"company\".\"noofemployeesunit\" AS \"noofemployeesunit\", \"dbo\".\"company\".\"county\" AS \"county\", \"dbo\".\"company\".\"sni\" AS \"sni\", \"dbo\".\"company\".\"mothercompany\" AS \"mothercompany\", \"dbo\".\"company\".\"latestupdate\" AS \"latestupdate\", \"dbo\".\"company\".\"creditinfo\" AS \"creditinfo\", \"dbo\".\"company\".\"istemplatecompany\" AS \"istemplatecompany\", \"dbo\".\"company\".\"erp_id\" AS \"erp_id\", \"dbo\".\"company\".\"erp_turnover_yearnow\" AS \"erp_turnover_yearnow\", \"dbo\".\"company\".\"erp_turnover_lastyear\" AS \"erp_turnover_lastyear\", \"dbo\".\"company\".\"lastcustomervisit\" AS \"lastcustomervisit\", \"dbo\".\"company\".\"goalvisits\" AS \"goalvisits\", \"dbo\".\"company\".\"noofvisits\" AS \"noofvisits\", \"dbo\".\"company\".\"latestsaleshistory\" AS \"latestsaleshistory\", \"dbo\".\"company\".\"mothercompanylime\" AS \"mothercompanylime\", \"dbo\".\"company\".\"acd_id\" AS \"acd_id\", \"dbo\".\"company\".\"acd_lastupdated\" AS \"acd_lastupdated\", \"dbo\".\"company\".\"acd_unittype\" AS \"acd_unittype\", \"dbo\".\"company\".\"acd_unitstatus\" AS \"acd_unitstatus\", \"dbo\".\"company\".\"acd_email\" AS \"acd_email\", \"dbo\".\"company\".\"acd_noofemployeesunit\" AS \"acd_noofemployeesunit\", \"dbo\".\"company\".\"acd_maintradecode\" AS \"acd_maintradecode\", \"dbo\".\"company\".\"acd_maintrade\" AS \"acd_maintrade\", \"dbo\".\"company\".\"acd_legalname\" AS \"acd_legalname\", \"dbo\".\"company\".\"acd_legalform\" AS \"acd_legalform\", \"dbo\".\"company\".\"acd_vatno\" AS \"acd_vatno\", \"dbo\".\"company\".\"acd_noofemployeescompany\" AS \"acd_noofemployeescompany\", \"dbo\".\"company\".\"acd_turnover\" AS \"acd_turnover\", \"dbo\".\"company\".\"acd_turnovercurrency\" AS \"acd_turnovercurrency\", \"dbo\".\"company\".\"acd_groupname\" AS \"acd_groupname\", \"dbo\".\"company\".\"credittemplaterating\" AS \"credittemplaterating\", \"dbo\".\"company\".\"credittemplatelastupdate\" AS \"credittemplatelastupdate\", \"dbo\".\"company\".\"potential\" AS \"potential\", \"dbo\".\"company\".\"invoiceaddress1\" AS \"invoiceaddress1\", \"dbo\".\"company\".\"invoiceaddress2\" AS \"invoiceaddress2\", \"dbo\".\"company\".\"invoicezipcode\" AS \"invoicezipcode\", \"dbo\".\"company\".\"invoicecity\" AS \"invoicecity\", \"dbo\".\"company\".\"fullinvoiceaddress\" AS \"fullinvoiceaddress\", \"dbo\".\"company\".\"emailinvoice\" AS \"emailinvoice\", \"dbo\".\"company\".\"erp_turnover_lastyeartodate\" AS \"erp_turnover_lastyeartodate\", \"dbo\".\"company\".\"erp_lastsynced\" AS \"erp_lastsynced\", \"dbo\".\"company\".\"erp_ytdgrowth\" AS \"erp_ytdgrowth\", \"dbo\".\"company\".\"erp_errormessage\" AS \"erp_errormessage\", \"dbo\".\"company\".\"erp_firstsynced\" AS \"erp_firstsynced\", \"dbo\".\"company\".\"erp_status\" AS \"erp_status\", \"dbo\".\"company\".\"erp_salestrend\" AS \"erp_salestrend\", \"dbo\".\"company\".\"acd_errormessage\" AS \"acd_errormessage\", \"coworker__via__coworker\".\"firstname\" AS \"coworker__via__coworker__firstname\", \"company__via__mothercompanylime\".\"name\" AS \"company__via__mothercompanylime__name\" FROM \"dbo\".\"company\" LEFT JOIN \"dbo\".\"coworker\" \"coworker__via__coworker\" ON \"dbo\".\"company\".\"coworker\" = \"coworker__via__coworker\".\"idcoworker\" LEFT JOIN \"dbo\".\"company\" \"company__via__mothercompanylime\" ON \"dbo\".\"company\".\"mothercompanylime\" = \"company__via__mothercompanylime\".\"idcompany\" WHERE (\"dbo\".\"company\".\"status\" = 0 AND \"dbo\".\"company\".\"buyingstatus\" = 108601)) \"source\" ",
  :params nil},
 :status :failed,
 :class com.microsoft.sqlserver.jdbc.SQLServerException,
 :stacktrace
 ["com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:265)"
  "com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1676)"
  "com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:615)"
  "com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:537)"
  "com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7730)"
  "com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:3786)"
  "com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:268)"
  "com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:242)"
  "com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:456)"
  "com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:1471)"
  "--> driver.sql_jdbc.execute$fn__55164.invokeStatic(execute.clj:363)"
  "driver.sql_jdbc.execute$fn__55164.invoke(execute.clj:361)"
  "driver.sql_jdbc.execute$execute_statement_or_prepared_statement_BANG_.invokeStatic(execute.clj:376)"
  "driver.sql_jdbc.execute$execute_statement_or_prepared_statement_BANG_.invoke(execute.clj:372)"
  "driver.sql_jdbc.execute$execute_reducible_query$fn__55246.invoke(execute.clj:500)"
  "driver.sql_jdbc.execute$execute_reducible_query.invokeStatic(execute.clj:499)"
  "driver.sql_jdbc.execute$execute_reducible_query.invoke(execute.clj:486)"
  "driver.sql_jdbc.execute$execute_reducible_query.invokeStatic(execute.clj:494)"
  "driver.sql_jdbc.execute$execute_reducible_query.invoke(execute.clj:486)"
  "driver.sql_jdbc$fn__91711.invokeStatic(sql_jdbc.clj:54)"
  "driver.sql_jdbc$fn__91711.invoke(sql_jdbc.clj:52)"
  "query_processor.context$executef.invokeStatic(context.clj:59)"
  "query_processor.context$executef.invoke(context.clj:48)"
  "query_processor.context.default$default_runf.invokeStatic(default.clj:67)"
  "query_processor.context.default$default_runf.invoke(default.clj:65)"
  "query_processor.context$runf.invokeStatic(context.clj:45)"
  "query_processor.context$runf.invoke(context.clj:39)"
  "query_processor.reducible$identity_qp.invokeStatic(reducible.clj:12)"
  "query_processor.reducible$identity_qp.invoke(reducible.clj:9)"
  "query_processor.middleware.cache$maybe_return_cached_results$maybe_return_cached_results_STAR___52623.invoke(cache.clj:220)"
  "query_processor.middleware.permissions$check_query_permissions$fn__48144.invoke(permissions.clj:109)"
  "metabase_enterprise.advanced_permissions.query_processor.middleware.permissions$check_download_permissions$fn__85604.invoke(permissions.clj:124)"
  "metabase_enterprise.sandbox.query_processor.middleware.column_level_perms_check$maybe_apply_column_level_perms_check$fn__87408.invoke(column_level_perms_check.clj:30)"
  "query_processor.middleware.mbql_to_native$mbql__GT_native$fn__51568.invoke(mbql_to_native.clj:23)"
  "query_processor$fn__54099$combined_post_process__54104$combined_post_process_STAR___54105.invoke(query_processor.clj:212)"
  "query_processor$fn__54099$combined_pre_process__54100$combined_pre_process_STAR___54101.invoke(query_processor.clj:209)"
  "query_processor.middleware.resolve_database_and_driver$resolve_database_and_driver$fn__52544$fn__52549.invoke(resolve_database_and_driver.clj:35)"
  "driver$do_with_driver.invokeStatic(driver.clj:75)"
  "driver$do_with_driver.invoke(driver.clj:71)"
  "query_processor.middleware.resolve_database_and_driver$resolve_database_and_driver$fn__52544.invoke(resolve_database_and_driver.clj:34)"
  "query_processor.middleware.fetch_source_query$resolve_card_id_source_tables$fn__48579.invoke(fetch_source_query.clj:349)"
  "query_processor.middleware.store$initialize_store$fn__48767$fn__48768.invoke(store.clj:11)"
  "query_processor.store$do_with_store.invokeStatic(store.clj:44)"
  "query_processor.store$do_with_store.invoke(store.clj:38)"
  "query_processor.middleware.store$initialize_store$fn__48767.invoke(store.clj:10)"
  "query_processor.middleware.normalize_query$normalize$fn__52816.invoke(normalize_query.clj:22)"
  "metabase_enterprise.audit_app.query_processor.middleware.handle_audit_queries$handle_internal_queries$fn__59641.invoke(handle_audit_queries.clj:130)"
  "query_processor.middleware.constraints$add_default_userland_constraints$fn__49849.invoke(constraints.clj:53)"
  "query_processor.middleware.process_userland_query$process_userland_query$fn__52755.invoke(process_userland_query.clj:145)"
  "query_processor.middleware.catch_exceptions$catch_exceptions$fn__53127.invoke(catch_exceptions.clj:167)"
  "query_processor.reducible$async_qp$qp_STAR___44982$thunk__44984.invoke(reducible.clj:100)"
  "query_processor.reducible$async_qp$qp_STAR___44982.invoke(reducible.clj:106)"
  "query_processor.reducible$async_qp$qp_STAR___44982.invoke(reducible.clj:91)"
  "query_processor.reducible$sync_qp$qp_STAR___44993.doInvoke(reducible.clj:126)"
  "query_processor$process_userland_query.invokeStatic(query_processor.clj:331)"
  "query_processor$process_userland_query.doInvoke(query_processor.clj:327)"
  "query_processor$fn__54146$process_query_and_save_execution_BANG___54155$fn__54158.invoke(query_processor.clj:342)"
  "query_processor$fn__54146$process_query_and_save_execution_BANG___54155.invoke(query_processor.clj:335)"
  "query_processor$fn__54190$process_query_and_save_with_max_results_constraints_BANG___54199$fn__54202.invoke(query_processor.clj:354)"
  "query_processor$fn__54190$process_query_and_save_with_max_results_constraints_BANG___54199.invoke(query_processor.clj:347)"
  "api.dataset$run_query_async$fn__69621.invoke(dataset.clj:69)"
  "query_processor.streaming$streaming_response_STAR_$fn__40100$fn__40101.invoke(streaming.clj:162)"
  "query_processor.streaming$streaming_response_STAR_$fn__40100.invoke(streaming.clj:161)"
  "async.streaming_response$do_f_STAR_.invokeStatic(streaming_response.clj:65)"
  "async.streaming_response$do_f_STAR_.invoke(streaming_response.clj:63)"
  "async.streaming_response$do_f_async$task__19006.invoke(streaming_response.clj:84)"],
 :card_id 11,
 :context :ad-hoc,
 :error "Invalid column name 'Buying status'.",
 :row_count 0,
 :running_time 0,
 :preprocessed

Hi @katja
With your description I would think you are hitting this issue:
https://github.com/metabase/metabase/issues/23449 - upvote by clicking :+1: on the first post

1 Like