切分字符
SqlServer切割字符串示例:
--declare @StrDId nvarchar(2000)
--set @StrDId='100,200,400,500,600'
--转换ID,防止注入
CREATE TABLE #table_DId( ID INT)
While(CHARINDEX(',',@StrDId)<>0)
Begin
Insert Into #table_DId(ID) Values(CONVERT(Int,Substring(@StrDId,1,CHARINDEX(',',@StrDId)-1)));
Set @StrDId=STUFF(@StrDId,1,CHARINDEX(',',@StrDId),'');
End
Insert Into #table_DId (ID) Values(CONVERT(Int,@StrDId));
/// <summary> /// 获取IP地址 /// </summary> public static string GetIPAddress() { string _result = string.Empty; _result = HttpContext.Current.Request.ServerVariables["HTTP_CDN_SRC_IP"]; if (string.IsNullOrEmpty(_result)) _result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; if (string.IsNullOrEmpty(_result)) _result = HttpContext.Current.Request.UserHostAddress; if (string.IsNullOrEmpty(_result) || !IsIP(_result)) return "127.0.0.1"; return _result; } /// <summary> /// 正则判断 /// </summary> private static bool IsIP(string ip) { return Regex.IsMatch(ip, "^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$"); }
begin try begin transaction commit transaction end try begin catch select ERROR_NUMBER() as errornumber,ERROR_LINE() as errorline,ERROR_MESSAGE() as errormessage rollback transaction end catch
for xml path
还有for json path转换json
--每行数据根节点row,数据列名子节点 select * from Table for xml path --path('参数')指定名称替换row;列名可以用as 替换 select Name as 'S-Name' from Table for xml path('') --单列纯文本:根节点用path('') +列名不命名;输出纯文本 select Name+'' from Table for xml path('')
每隔2个字符插入冒号
select t.*, rtrim(substr(value, 1, 2) ||bai ':' || substr(value, 3, 2) || ':' || substr(value, 5, 2) || ':' || substr(value, 7, 2), ':') value2 from test_split t;
组内排序
select AN, BN,10+ROW_NUMBER() OVER (PARTITION BY 分组列 ORDER BY 排序列) AS NUM from #temp
资料
https://www.cnblogs.com/yasuo2/p/6433697.html