sql server的使用筆記
一、比較複雜的update語句:update .. from
update t_buymaterialreceivestoredetail
set qcid = a.qcid,
qcqty = isnull(a.qcqty,a.qty),
qcpricepercent = isnull(a.qcpricepercent,1),
qcfailedqty = isnull(a.qcfailedqty,0),
qcwasteqty = isnull(a.qcwasteqty,0),
qcshortqty = isnull(a.qcshortqty,0),
qcpercent = isnull(a.qcpercent,1),
note = a.note,
determineresult=a.determineresult
from (select * from t_temp_buymaterialreceivestoredetail
where operateid = @operateid
and operatetime = @operatetime
and qcid = qcid) a
where t_buymaterialreceivestoredetail.buyid = a.buyid
and t_buymaterialreceivestoredetail.materialitemid = a.materialitemid
and t_buymaterialreceivestoredetail.receiveid = a.receiveid
and t_buymaterialreceivestoredetail.storeid = a.storeid
and t_buymaterialreceivestoredetail.materialcolorid = a.materialcolorid
and t_buymaterialreceivestoredetail.materialsizeid = a.materialsizeid
and t_buymaterialreceivestoredetail.saleid = a.saleid
and t_buymaterialreceivestoredetail.styleid = a.styleid
二、判斷varchar型的資料是否空
len(note)= 0
三、將資料庫的表的表結構的ntext型別的字段改為nvarchar(max)
select 'alter table ' + c.name+' alter column '+a.name+' nvarchar(max)'
from sys.columns a
left join sys.types b on a.system_type_id = b.system_type_id and b.name='ntext'
left join sys.objects c on a.object_id = c.object_id and c.type='u'
where b.name='ntext' and c.type='u'
四、巧妙的將返回的所有行的記錄以一行字串的形式輸出
declare @str varchar(8000)
select @str = isnull(@str,'')+salecode+char(13) from t_sale
select @str
五、處理bit的型別的資料不能max
max(cast(a.state as int))
六、對調資料庫中的兩行記錄的某個欄位的值
update t_reportconfig
set array = case
when reportconfigid = 17 then (select array from t_reportconfig where reportconfigid=18)
else (select array from t_reportconfig where reportconfigid=17)
endwhere reportconfigid in (17,18)
個人解釋:sql編譯時,先計算了()中的值,所以巧妙的達到了互動兩個值
七、delete exists
delete from a
where exists(select *
from b a
where a.column = a.column)
八、object_id (transact-sql)
returns the database object identification number of a schema-scoped object. 物件標識號
語法:object_id ( '[ database_name . [ schema_name ] . | schema_name . ]
object_name' [ ,'object_type' ] )
例子:select count(1) from syscolumns where [id]=object_id('t_operator') and [name]='operatorid'
九、資料庫中物件是否存在
1.表中的列
select count(1) from syscolumns where [id]=object_id('t_operator') and [name]='operatorid'
2.表
select count(*) from sysobjects
where id = object_id(n'[t_operator]') and objectproperty(id, n'isusertable') = 1
十、sqlserver字串前加n
加上 n 代表存入資料庫時以 unicode 格式儲存。
n'string' 表示string是個unicode字串
unicode 字串的格式與普通字串相似,但它前面有乙個 n 識別符號(n 代表 sql-92 標準中的國際語言 (national language))。
unicode 常量確實有排序規則,主要用於控制比較和區分大小寫
十一、objectproperty
returns information about objects in the current database
this 的使用 筆記
this指標 在類的每乙個成員函式的形參表中都有乙個隱含的指標變數this,該指標變數的型別就是成員函式所屬類的型別 當程式中呼叫類的成員函式時,this指標變數被自動初始化為發出函式呼叫的物件的位址 this的使用 1 區分成員和非成員 2 乙個類的方法需要返回當前物件的引用 qs set int...
wireshark的使用筆記
最近在閱讀林沛滿編寫的兩本關於wireshark的書,寫作風格與以往看過的技術文章不同,我比較喜歡這種寫作風格,知識點在不經意間就慢慢進入了你的腦海,不錯。這篇文章我應該會不定期修改一下,以記錄使用wireshark中的一些事情。1.限制單包大小 可以通過限制每個包的尺寸來減少整個抓包檔案的大小。舊...
thymeleaf的使用筆記
整合springmvc 前後互動 springmvc html ids activityid,status 0 success function data function updateactivity activityid success function data function addact...