Replacement for Left command in SQLite SQL

烈酒焚心 提交于 2021-02-05 09:16:07

问题


I have the following query that works fine in MS Access, MySQL and SQL Server but when I try to use it in SQLite I get an error:

near "(": syntax error:

I can't find the Left command in any documentation of SQLite so I guess it isn't there but how could I get it to work then.

SELECT 
    Left(fldcall, 3) AS Group1, 
    Mid(fldcall, 4, 1) AS Group2, 
    tblcalls.*, 
    tblzip.fldcity
FROM 
    tblcalls 
LEFT JOIN 
    tblzip ON tblcalls.fldzipcode = tblzip.fldzipcode;

回答1:


You can use the substr() function instead:

SELECT substr(fldcall, 1, 3) AS Group1,
       substr(fldcall, 4, 1) AS Group2,
       tblcalls.*,
       tblzip.fldcity
FROM tblcalls
LEFT JOIN tblzip USING (fldzipcode);


来源:https://stackoverflow.com/questions/36370304/replacement-for-left-command-in-sqlite-sql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!