随笔分类 -  sql server

摘要:-- 列转行拼接 select stuff((select ','+字段名 from 表名 for xml path('')),1,1,'') -- 示例 select stuff((select ','+user_name from t_user for xml path('')),1,1,'') 阅读全文
posted @ 2024-12-05 14:05 一隅桥畔 阅读(8) 评论(0) 推荐(0) 编辑
摘要:-- sql server生成uuid select newid(); -- 替换- select replace(newid(),'-',''); 阅读全文
posted @ 2024-04-01 17:17 一隅桥畔 阅读(218) 评论(0) 推荐(0) 编辑
摘要:-- 字段设置默认值 alter table t_ward add default 0 for valid; 阅读全文
posted @ 2023-10-09 18:19 一隅桥畔 阅读(80) 评论(0) 推荐(0) 编辑
摘要:-- sql server分组排序取出每组顺序第一条 select * from ( select *,row_number() over(partition by bloodbag_id order by operation_date desc) rn from tt_blood_log )t w 阅读全文
posted @ 2023-09-26 15:32 一隅桥畔 阅读(398) 评论(0) 推荐(0) 编辑
摘要:select dateadd(minute,-10,getdate());-- 减10分钟 select dateadd(hour,-10,getdate());-- 减10小时 select dateadd(day,-10,getdate());-- 减10天 阅读全文
posted @ 2023-07-07 14:56 一隅桥畔 阅读(211) 评论(0) 推荐(0) 编辑
摘要:alter table t_user add constraint UK_user_code -- 指定约束的名称 unique (user_code) -- 指定唯一键的列名 go 阅读全文
posted @ 2023-07-05 23:33 一隅桥畔 阅读(126) 评论(0) 推荐(0) 编辑
摘要:-- 创建触发器 CREATE TRIGGER tr_t_user_update_time ON t_user -- 触发时机、条件 AFTER UPDATE AS BEGIN SET NOCOUNT ON; UPDATE t_user SET update_time = SYSDATETIME() 阅读全文
posted @ 2022-12-15 14:56 一隅桥畔 阅读(488) 评论(0) 推荐(0) 编辑
摘要:-- SQL根据字符串排序 order by cast(card_no as int) 阅读全文
posted @ 2022-11-10 15:32 一隅桥畔 阅读(242) 评论(0) 推荐(0) 编辑
摘要:update tb_user set des = replace(des, '你好', '啦啦啦'); 阅读全文
posted @ 2022-11-07 10:10 一隅桥畔 阅读(96) 评论(0) 推荐(0) 编辑
摘要:--执行语句生成函数fn_GetPy create function fn_GetPy(@str nvarchar(4000)) returns nvarchar(4000) --WITH ENCRYPTION as begin declare @intLen int declare @strRet 阅读全文
posted @ 2022-09-13 19:06 一隅桥畔 阅读(70) 评论(0) 推荐(0) 编辑
摘要:-- 1、匹配一个字段 比如user_name select * from tb_user where user_name like '%'+ #{keyWord} +'%'; select * from tb_user where user_name like concat('%',#{keyWo 阅读全文
posted @ 2022-08-10 23:53 一隅桥畔 阅读(4973) 评论(0) 推荐(0) 编辑
摘要:-- 批量删除重复数据 delete t from ( select row_number() over(partition by user_code order by id) as rowNumber,* from t_user )t where t.rowNumber > 1 阅读全文
posted @ 2022-07-29 15:36 一隅桥畔 阅读(109) 评论(0) 推荐(0) 编辑
摘要:select left(str,len(str)-1) -- 非空校验 select case when len(str)>1 then left(str,len(str)-1) else str end 阅读全文
posted @ 2022-05-11 23:18 一隅桥畔 阅读(165) 评论(0) 推荐(0) 编辑
摘要:-- 去除左侧空格ltrim() select ltrim(' abc');-- abc -- 去除右侧空格rtrim() select rtrim('abc ');-- abc -- 去除两侧空格 select ltrim(rtrim(' abc '));-- abc 阅读全文
posted @ 2022-04-25 14:58 一隅桥畔 阅读(998) 评论(0) 推荐(0) 编辑
摘要:-- 打开 set identity_insert [表名] on -- 关闭 set identity_insert [表名] off -- 注:IDENTITY_INSERT默认是OFF 阅读全文
posted @ 2022-04-24 20:18 一隅桥畔 阅读(851) 评论(0) 推荐(1) 编辑
摘要:-- 执行得到批量删除语句 select CONCAT('drop table ', table_name, ';') from information_schema.tables where table_name like 'pre_%'; -- 执行结果: drop table pre_acco 阅读全文
posted @ 2022-04-01 16:26 一隅桥畔 阅读(245) 评论(0) 推荐(0) 编辑
摘要:-- MYSQL SELECT UUID(); -- 将'-'符号替换掉 SELECT REPLACE(UUID(), '-', ''); -- SQL SERVER SELECT NEWID(); -- 将'-'符号替换掉 SELECT REPLACE(NEWID(), '-', ''); -- 阅读全文
posted @ 2022-02-09 09:22 一隅桥畔 阅读(1233) 评论(0) 推荐(0) 编辑
摘要:-- 转换成大写 SELECT UPPER('a'); -- 转换成小写 SELECT LOWER('A'); 阅读全文
posted @ 2022-02-09 09:08 一隅桥畔 阅读(481) 评论(0) 推荐(0) 编辑
摘要:--ROUND函数 SELECT ROUND(12.3456 , 2) --12.3500 SELECT ROUND(12.3456 , 0) --12.0000 SELECT ROUND(12.3456 , -1) --10.0000 SELECT ROUND(12.3 , 2) --12.3 - 阅读全文
posted @ 2022-01-28 10:09 一隅桥畔 阅读(4176) 评论(0) 推荐(0) 编辑
摘要:SQL中CONCAT()、CONCAT_WS()和GROUP_CONCAT()函数的用法CONCAT()函数语法:CONCAT(str1, str2, ...)将多个字符串连接成一个字符串SELECT CONCAT(id, name, age) FROM tb_user;结果: CONCAT_WS( 阅读全文
posted @ 2021-12-04 10:50 一隅桥畔 阅读(4569) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示