## 1 Introduction  
The transition from paper-based medical records to electronic health records (EHR) represents a significant technological advancement in modern healthcare. EHR systems serve as central repositories of patient information, encompassing medical histories, diagnostic results, treatment plans, and administrative data. They are essential to improve care coordination, reduce errors, and enable evidence-based decision-making [1]. Despite their fundamental role in the modernization of healthcare care, the sheer volume and diversity of data within EHR systems, ranging from structured data such as laboratory values to unstructured data such as physician notes, pose significant challenges for healthcare providers and researchers [2]. In recent years, cutting-edge technologies, especially those based on artificial intelligence (AI) and natural language processing (NLP), have revolutionized the utilization of EHR systems. Advanced NLP models such as BioBERT, ClinicalBERT, and Med-PaLM (Med-PaLM: an LLM from Google for medical domain [[https://sites.research.google/med-palm/](https://sites.research.google/med-palm/)]([https://sites.research.google/med-palm/](https://sites.research.google/med-palm/)) accessed on 26 January 2025) have shown impressive abilities in obtaining actionable insights from unstructured clinical text. These capabilities facilitate automated diagnosis coding, summarizing patient encounters, and performing predictive analytics [3; 4; 5]. Moreover, integrating large-scale language models (LLMs) fine-tuned into medical corpora has opened new possibilities to improve patient safety, accelerate research, and personalize care [6]. Beyond NLP, interoperability solutions such as FHIR (fast healthcare interoperability resources) have facilitated seamless data exchange between disparate systems, addressing one of the most persistent challenges in implementing EHR [7]. Furthermore, advances in cloud computing and blockchain technologies are improving data security, scalability, and access control, ensuring compliance with stringent privacy regulations such as GDPR and HIPAA [8; 9]. Despite these advancements, several challenges remain. Issues such as clinician burnout due to excessive documentation, data security and privacy concerns, and the high system integration costs continue to hinder the full potential of EHR systems [10]. Moreover, ensuring equitable access to these innovations in low-resource settings is an ongoing concern [11]. Creating precise SQL queries from natural language inputs is essential for allowing healthcare personnel to engage with intricate databases. These advancements in using LLMs for converting natural language to SQL queries align with broader trends in healthcare informatics, where user-friendly tools are becoming indispensable for navigating the vast amounts of structured and unstructured data. In the context of EHR systems, this capability has significant implications. For example, a clinician could query patient cohorts with specific comorbidities or treatment regimens directly in natural language, bypassing specialized database expertise. This democratization of database access has the potential to improve clinical decision-making, reduce administrative bottlenecks, and accelerate research. However, the healthcare domain presents unique challenges that require customized solutions. Often characterized by abbreviations, synonyms, and context-dependent meanings, medical terminology remains a barrier to accurate query generation. Furthermore, the complexity of healthcare databases, such as those built on MIMIC-3, with their intricate schemas and interrelated tables, adds another difficulty for general-purpose models. The paper's contributions are as follows. First, this study aims to systematically evaluate the effectiveness of state-of-the-art large language models (LLMs) in transforming medical queries into executable SQL statements, with a focus on accuracy, consistency, and cost-efficiency.