输入表有数据,结果表读取输入表的所有数据,检查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模板网!
修改现有小数位信息Modify Existing decimal places info(修改现有小数位信息)
多次指定相关名称“CONVERT"The correlation name #39;CONVERT#39; is specified multiple times(多次指定相关名称“CONVERT)
T-SQL 左连接不返回空列T-SQL left join not returning null columns(T-SQL 左连接不返回空列)
从逗号或管道运算符字符串中删除重复项remove duplicates from comma or pipeline operator string(从逗号或管道运算符字符串中删除重复项)
将迭代查询更改为基于关系集的查询Change an iterative query to a relational set-based query(将迭代查询更改为基于关系集的查询)
将零连接到 sql server 选择值仍然显示 4 位而不是concatenate a zero onto sql server select value shows 4 digits still and not 5(将零连接到 sql server 选择值仍然显示 4 位而不是 5)