Tag: SQL
SQL脚本-利用带关联子查询Update语句更新数据与连接远程服务器
Update Table1 set c = (select c from Table2 where a = Table1.a) where c is null
SQL脚本-相除与四舍五入
SELECT CASE WHEN ISNULL(A+B,0)<>0 THEN
LTRIM(CONVERT(DEC(18,2),A*100.0/(A+B)))+'%' ELSE '' END AS '百分数'
SQL脚本-对字段出现NULL值的处理以及COUNT
select case when '字段名' is null then '\N' else convert(varchar(20),'字段名') end as 'NewName'
SQL脚本-SQL换行
对于由 FOREIGN KEY 约束引用的表,不能使用 TRUNCATE TABLE,而应使用不带 WHERE 子句的 DELETE 语句。由于 TRUNCATE TABLE 不记录在日志中,所以它不能激活触发器。
SQL脚本-行列互转/替换字符串 substring replace
行业互转SQL脚本create table test(id int,name varchar(20),quarter int,profile int) insert into test values(1,'a',1,1000)insert into test values(1,'a',2,2000)