SQL编写自定义函数
2024-10-06 23:49:31
-- 通过一个子级ID 返回一级分类名称
alter function calcclass
(@dclassid as int)
returns varchar(50)
as
begin
-- 通过一个子级ID 返回一级分类名称
-- 返回ID 和父级分类ID 直到父级分类ID=0
declare @cid int
declare @cfatherid int
set @cid=@dclassid
while (@cid>0)
select @cfatherid=cid,@cid=cfatherid from trd_archivesclass where cid=@cid
return (select cname from trd_archivesclass where cid=@cfatherid)
end
如果需要在 Sql Server 中批量插入日期,可采用以下语句:
DECLARE @i int
SET @i = 0
WHILE @i < 365
BEGIN
INSERT INTO table1
( Day1 ,Flag2 ,AddTime3 )
VALUES ( DATEADD(DAY,@i,'2015-1-1') ,1,GETDATE() )
SET @i = @i + 1
END
最新文章
- (利用tempdata判断action是直接被访问还是重定向访问)防止微信活动中用户绕过关注公众号的环节
- 《Qt Quick 4小时入门》学习笔记
- hdu2094 set初体验
- memcached(二)事件模型源码分析
- rpyc 回调模式工作不正常
- 在Ubuntu 12.04安装和设置Samba实现网上邻居共享
- PHP Array函数分类
- const与define的异同
- Introduction to neural network —— 该“神经网络” 下拉“祭坛”
- maven添加本地依赖包方法
- 实现基本TCP套接字客户端
- 蓝桥杯-隔行变色-java
- Java图形界面学习---------简易登录界面
- antlr v4 使用指南连载2——准备环境
- 解决 spring-cloud-starter-zipkin 启动错误
- json的xpath:简易数据查询
- windows7安装dlib过程中遇到的问题总结以及运行实例效果
- java标志性接口
- 微信小程序wxml無法實現頁面跳轉的問題
- (转载)intellj idea 如何设置类头注释和方法注释
热门文章
- JVM学习笔记(一,待整理)
- Action向视图传值的6种方式(转)
- innodb存储引擎之内存
- BZOJ 1003 最短路dp
- 不使用C库函数(Sprintf)将void* 指针转换为十六进制字符串
- target runtime com.genuitec.runtime.genuitec.jee60 is not defined
- linux编译esp8266
- [Algorithm] Finding Prime numbers - Sieve of Eratosthenes
- 钉钉报警-prometheus-alertmanager
- 前端基础教程-jQuery EasyUI 的EasyLoader实例