刷数据某个字段使用
update tab1 set 列名 = b.列名 from tab1 a
inner join tab2 b on a.列名= b.列名
视图连接
select *FROM OPENROWSET('sqloledb', 'IP地址'; '用户名'; '密码', [数据库名].dbo.表名)
截断特定字符后变成新字段
SUBSTRING(列名·,charindex('特定字符',列名)+1,len(列名)) as 新列名
数据去掉指定字符
update 表名 set 列名= replace(列名,'指定字符','');
ISNUMERIC函数
isnumeric( )还是一个很实用的函数,在算法题目里面应该会有比较大的作用。
检测字符串是否只由数字组成,如果字符串中只包括数字,就返回Ture,否则返回False。
SqlServer中Exists的使用
Exists(select):若子查询的结果非空时,返回true;结果为空,返回false。
Not Exists(select):若子查询的结果非空时,返回false;为空时,返回true。
可以用来替换in和not in
replace函数
replace(需要替换的数据表字段,要替换的字符,替换成的字符)
datediff() 函数
SELECT DATEDIFF(day,'2008-12-29','2008-12-30') AS DiffDate
返回值是1
查询数据表中的字段说明
SELECT t.[name] AS 表名,c.[name] AS 字段名,cast(ep.[value]
as varchar(100)) AS [字段说明]
FROM sys.tables AS t
INNER JOIN sys.columns
AS c ON t.object_id = c.object_id
LEFT JOIN sys.extended_properties AS ep
ON ep.major_id = c.object_id AND ep.minor_id = c.column_id WHERE ep.class =1
AND t.name='数据表名'
int类型数据拼接成字符串
SELECT CAST(student_id AS VARCHAR) + ' - ' + student_name AS student_info
FROM student_table
数据表去除字段中的换行符
REPLACE(@str, CHAR(10), '')