本文介紹了使用游標和表變量的 SQL 查詢的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
輸入表有數據,結果表讀取輸入表的所有數據,檢查Name列的長度,打印結果表中<=5的長度
Input table is having data and result table should read all the data from input table and check the length of Name column and should print the length which is <=5 in result table
在此處輸入圖片說明在此處輸入圖片描述
你能否建議使用循環(IF else)......比如使用條件讀取數據,即<=5,并通過插入語句將其存儲在臨時表變量中,并通過使用最終選擇語句我們得到輸出...請幫忙
can you please suggest using loops (IF else) ...like reading the data using conditions i.e. <=5, and by insert statement storing it in a temporary table variable and by using final select statement we are getting the output... plz help
推薦答案
只需使用 LEN()
函數和 case
表達式:
Just use LEN()
function with case
expression :
select t.id,
(case when len(name) <= 5
then concat(name, '_', len(name))
else name
end) as name,
age
from table t
這篇關于使用游標和表變量的 SQL 查詢的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!