創(chuàng)建示例數(shù)據(jù)
select top 10 * into 創(chuàng)建表 from 原始表 where Creator='and??content like '%'+char(13)+'%' or content like '%'+char(10)+'%' and CreateDate between '2006-02-15 08:02:42.000 'and '2006-02-10 08:30:00.000'
得到當(dāng)前時間 convert(varchar(19),getdate(),120)
得到提前一天的時間 select??convert(varchar(10),dateadd(d,1,getDate()),120)
連接字段
SELECT RTRIM(StarYear) + '-' + RTRIM(StarMonth) + '-' + RTRIM(StarDay)
??????AS StarDate
FROM STAR
刪除重復(fù)的數(shù)據(jù)
利用索引把數(shù)據(jù)導(dǎo)入到一個沒有重復(fù)的臨時表insert into 中間表 select * from 原表,(這個過程通過索引設(shè)置,清除重復(fù)的數(shù)據(jù)或可以通過加distanct)
然后導(dǎo)出 delete from 原表 insert into 原表 select * from 中間表 delete from 中間表
BEGIN
declare @max int,@id nvarchar(50)
declare cur_rows cursor local for select 標(biāo)識字段,count(*) from 表名 group by 標(biāo)識字段 having count(*)>1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
select @max = @max-1
set rowcount @max
delete from??表名 where 標(biāo)識字段
=@id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0
END
截取字符串
select substring('2008-06-24 00:00:00.000',0,12)
轉(zhuǎn)化數(shù)據(jù)類型
select convert(varchar,getdate(),120)
給表添加新字段
alter table Cha_TradeIndex add Avg5Price decimal(28,2)
建立索引
--原則 大表建索引,先插入數(shù)據(jù)后建立索引, 為保證數(shù)據(jù)唯一性,先建立索引
create index idx#表名$字段 on 表名 (字段)
在查詢的時候,用到case語句
SELECT??
??a.f022n_0160?? CurYearProfit,
??case when a.f002n_0160 =0 then 0
????when a.f002n_0160 >0 then (f004n_0160-f006n_0160)/f002n_0160 * 100
????end sadio,--字段顯示名
??b.F041v_0002????Industry
from tb_trade_0160 a,tb_company_0002 b
where??a.ob_secName_0160 = b.f001v_0002
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
