2011-09-24 14 views
3

我知道在SQLite中,我們使用LENGTH函數而不是len。但是,當我想用​​LENGTH功能使用子查詢,像這樣:如果它有一個SQL表達式,如果它有一個帶SUBSELECT查詢的LENGTH函數到SQLite

select length(select name from tblNames where name=1) 

我收到一個錯誤。下面是微軟版本的SQL表達式:

iif(len((select BilgiAcik from DigerBilg where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)))>0,(select BilgiAcik from DigerBilg where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)),Cstr(Dr.Fr)) as Fr, 

我轉換了上述表達式爲SQLite作爲這樣:

(case length((select BilgiAcik from DigerBilg where BilgTip=12 and BilgDgr=CAST(Dr.Fr as TEXT))>0 (select BilgiAcik from DigerBilg where BilgTip=12 and BilgDgr=Cstr(Dr.Fr)) else CAST(Dr.Fr as TEXT) end) as Fr, 

什麼,我做錯了什麼?我不能只使用SUBSELECT查詢與LRNGTH函數?有關如何解決此問題的任何建議?

回答

2

您會希望重構您的語句,使其更接近於以下內容。

select length(name) from (select name from tblnames where name=1); 

如果你喜歡,你可以通過別名選擇別名來更容易地管理這個。

select length(t.name) from (select name from tblnames where name=1) as t; 
+1

非常感謝你 –

相關問題