js中换行标签替换成\n
zgremark = zgremark.replace(/<br\s*/?>/gi, '\n');
合并多行查询数据到一行:使用自连接、FOR XML PATH('')、STUFF或REPLACE函数
select id,
[val]=( SELECT [value] +','
FROM tb AS b
WHERE b.id = a.id
FOR XML PATH('') )
FROM tb AS a
SUBSTRING(expression,start,length)
参数
expression
是字符串、二进制字符串、text、image、列或包含列的抒发型。不要施用包含聚合函数的抒发型。
start
是一个整数,指定子串的起头位置。
length
是一个整数,指定子串的长度(要返回的字符数或字节数)。
js生成随机数
//生成GUID
function guid() {
return 'xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
};
js禁止鼠标右键
//禁止鼠标右键菜单 20160420
function stop() {
return false;
}
document.oncontextmenu = stop; //禁用鼠标右键
document.ondragstart = stop; //禁止拖动
document.onselectstart = stop; //禁止选择
SQL中EXISTS的用法
EXISTS子句可以用if(){}else(){}判断
EXISTS用于检查子查询是否至少会返回一行数据,该子查询实际上并不返回任何数据,而是返回值True或False
EXISTS 指定一个子查询,检测 行 的存在。
例子:
begin
IF EXISTS(select * from OPM3_App_Menu_User where usercode='00000000')
update OPM3_App_Menu_User set menuid='1,2,3' where usercode='00000000'
else
insert into OPM3_App_Menu_User(usercode,menuid) values('00000000','1,2,3,4,5,6,7')
end
sql把逗号隔开的字符串变成数据表charindex
select b.v_dlid,a.v_xm from pt_yhmc as a
inner join pt_login as b on a.v_yhdm=b.v_yhdm
where (charindex(a.v_xm,'龙博威,张瑞瑞,黄龙龙,王鹏,管理员,李雷,杨幂,韩红')<>0)
sql语句FOR XML PATH('')和charindex结合使用
select
(select v_xm+',' from pt_yhmc as b
where (charindex(b.v_yhdm,(select a.monitor from OPM_EPCM_IntendanceMaster as a where a.intendanceguid='7B62C515-CBEE-4F0A-9E00-053342F2FB70'))<>0)
for xml path(''))as viewuser,a.monitor,* from OPM_EPCM_IntendanceMaster as a where a.intendanceguid='7B62C515-CBEE-4F0A-9E00-053342F2FB70'
例子(表结构):
select a.intendanceguid,
(select v_xm+',' from pt_yhmc as b
where (charindex(b.v_yhdm,(select a.monitor from OPM_EPCM_IntendanceMaster as f where
f.intendanceguid=a.intendanceguid))<>0)
for xml path(''))as monitor,
a.monitor,* from OPM_EPCM_IntendanceMaster as a