SQL中只有两列数据(字段1,字段2),将其相同字段1的行转列 转换前: 转换后: --测试数据 if not object_id(N'Tempdb..#T') is null drop table #T Go Create table #T([MDF_LOT_NO] int,[ERP_MODE_CD] int) Insert #T , union all , union all , union all , Go --测试数据结束 DECLARE @name VARCHAR(max),@sql
ORDER BY 后可加2个字段,用英文逗号隔开. 1.f1用升序, f2降序,sql该这样写: 1 ORDER BY f1, f2 DESC 2.也可以这样写,更清楚: 1 ORDER BY f1 ASC, f2 DESC 3.如果都用降序,必须用两个desc: 1 ORDER BY f1 DESC, f2 DESC
declare v_cnt number; V_SQL VARCHAR2 (500) := '';begin select count(*) into v_cnt from dual where exists(SELECT * FROM USER_TAB_COLUMNS WHERE TABLE_NAME = UPPER('TB_FDN_DEVICEACCOUNT') AND COLUMN_NAME = 'NSBFL'); if v_cnt = 0 then V_SQL := 'ALTE
最近在项目中遇到个问题,需要将表中某列字段合并成字符串输出,如果直接通过代码全部读取出来,再遍历进行拼接显然不是最好的方法,所以想着能否在数据读取的时候直接拼接好返回,网上搜了可通过for xml来实现. 首先,准备好需要的数据,脚本如下: if exists (select * from sysObjects where id=object_id('Student')) drop table Student go create table Student ( Id int, Name ) )