比如字段sid中用'|'分割的一些字符 a|b|c|d,需要通过sql查询出字符的个数是4. 可以使用如下脚本: SELECT LEN(sid)-LEN(REPLACE(sid,'|',''))+1 'NUM1',COUNT(1)'NUM2' FROM dbo.FM_PurchaseRequest WHERE ISNULL(sid,'')<>'' GROUP BY LEN(sid)-LEN(REPLACE(sid,'|',''))+1 ORDER BY 附件个数 DESC
原文:sqlserver查询所有表的行数的sql语句 select object_name(id),rowcnt from sysindexes where indid<2 and objectproperty(id,'ismsshipped')=0 order by rowcnt desc select a.name, b.rows from sysobjects a inner join sysindexes b on a.id = b.id where a.type = 'u' and b
SQLServer 查询数据死锁语句 我们可以通过以下SQL 语句用来查询,当前数据中存在的死锁语句,定位数据库出现死锁的根本原因. --每秒死锁数量 SELECT * FROM sys.dm_os_performance_counters WHERE counter_name LIKE 'Number of Deadlocksc%'; --查询当前阻塞 WITH CTE_SID ( BSID, SID, sql_handle ) AS ( SELECT blocking_session
Sql动态查询拼接字符串的优化 最原始的 直接写:string sql="select * from TestTables where 1=1";... 这样的代码效率很低的,这样影响了数据库的索引引用如下所示:private void TestOneMethod() { string querySql = "select * from TestTables where 1=1"; if (hasOneCo
golang 中获取字符串个数 在 golang 中不能直接用 len 函数来统计字符串长度,查看了下源码发现字符串是以 UTF-8 为格式存储的,说明 len 函数是取得包含 byte 的个数 // string is the set of all strings of 8-bit bytes, conventionally but not // necessarily representing UTF-8-encoded text. A string may be empty, but //
最近搞报表的项目,要写数据库sql语句,根据状态值查询状态的个数,这个开始难为到我了,不过已经有解决办法了. 在数据库表中有一个字段是状态(zt),这里面有1-7这7个状态,现在查询每个状态的数量,并且显示在一张表中,正常情况下查状态是: SELECT COUNT(*) draft FROM `it_project_info` WHERE `it_project_info`.item_status`='1'; SELECT COUNT(*) checks FROM `it_project_in
字段初始化规律: 当执行如下代码时 class InitializeBlockClass{ public int field=100; { field=200; } public InitializeBlockClass(int value) { this.field=value; } public InitializeBlockClass(){ } { field=150; } } public class Work { public static void main(String[] arg
, , '') ) AS c_departNames FROM t_user AS A LEFT JOIN t_role AS B ON A.c_roleId=B.c_roleId 用 CHARINDEX(','+LTRIM(c_departId)+',',','+A.c_departIds+',')>0 来解决 c_departId为int类型 A.c_departIds为字符串类型
当使用:SELECT ','+Id FROM dbo.Test FOR XML PATH('')); //这样读取的数据虽然是1,2,3,4,但是仍然是xml格式,所以当数据超过2033时候,用sqldatereader或者sqldateadapter读取数据会截断xml文件. 此时要:SELECT STUFF((SELECT ','+Id FROM dbo.Test FOR XML PATH('')),1,1,'');//利用stuff函数将xml文件转换为一个字符串字段.就不会截断.
create function [dbo].[mergeName](@Id bigint) returns nvarchar(500) as begin declare @str nvarchar(500) set @str = '' select @str = @str + ',' + cast(CompanyUserName as nvarchar(500)) + cast(Mobile as nvarchar(500)) from
CREATE PROCEDURE [dbo].[Pro_TEST] AS BEGIN ) ) SET @split=',' SET @c='025,023,014,015' )) ) BEGIN INSERT #T( col ) , ) ) , CHARINDEX(@split, @c), '') END INSERT #T( col ) VALUES ( @c ) SELECT * FROM #T END GO --execute Pro_TEST