SQL一些小技巧
来源:互联网 发布:炒股哪个软件最好 编辑:程序博客网 时间:2024/05/02 04:29
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
ThesehasbeenpickedupfromthreadwithinSQLjunkiesForumshttp://www.SQLjunkies.com
Problem
TheproblemisthatIneedtorounddifferently(byhalves)
Example:4.24roundsto4.00,but4.26roundsto4.50.
4.74roundsto4.50and4.76roundsto5.00
Solution
declare@tfloat
set@t=100.74
selectround(@t*2.0,0)/2
Problem
I'mwritingafunctionthatneedstotakeinacommaseperatedlistandusitinawhereclause.Theselectwouldlooksomethinglikethis:
select*frompeoplewherefirstnamein('larry','curly','moe')
Solution
usenorthwind
go
declare@xVarvarchar(50)
set@xVar='anne,janet,nancy,andrew,robert'
select*fromemployeeswhere@xVarlike'%'+firstname+'%'
Problem
NeedasimplepagingSQLcommand
Solution
usenorthwind
go
select*fromproductsa
where(selectcount(*)fromproductsbwherea.productid>=b.productid)between15and16
Problem
Performcase-sensitivecomparisionwithinSQLstatementwithouthavingtousetheSETcommand
Solution
usenorhtwind
go
SELECT*FROMproductsASt1
WHEREt1.productnameCOLLATESQL_EBCDIC280_CP1_CS_AS='Chai'
--executethiscommandtogetdifferentcollatenaming
--select*from::fn_helpcollations()
Problem
Howtocallastoredprocedurelocatedinadifferentserver
Solution
SETNOCOUNTON
usemaster
go
EXECsp_addlinkedserver'172.16.0.22',N'SQLServer'
go
Execsp_link_publication@publisher='172.16.0.22',
@publisher_db='Northwind',
@publication='NorthWind',@security_mode=2,
@login='sa',@password='sa'
go
EXEC[172.16.0.22].northwind.dbo.CustOrderHist'ALFKI'
go
execsp_dropserver'172.16.0.22','droplogins'
GO
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
ThesehasbeenpickedupfromthreadwithinSQLjunkiesForumshttp://www.SQLjunkies.com
Problem
TheproblemisthatIneedtorounddifferently(byhalves)
Example:4.24roundsto4.00,but4.26roundsto4.50.
4.74roundsto4.50and4.76roundsto5.00
Solution
declare@tfloat
set@t=100.74
selectround(@t*2.0,0)/2
Problem
I'mwritingafunctionthatneedstotakeinacommaseperatedlistandusitinawhereclause.Theselectwouldlooksomethinglikethis:
select*frompeoplewherefirstnamein('larry','curly','moe')
Solution
usenorthwind
go
declare@xVarvarchar(50)
set@xVar='anne,janet,nancy,andrew,robert'
select*fromemployeeswhere@xVarlike'%'+firstname+'%'
Problem
NeedasimplepagingSQLcommand
Solution
usenorthwind
go
select*fromproductsa
where(selectcount(*)fromproductsbwherea.productid>=b.productid)between15and16
Problem
Performcase-sensitivecomparisionwithinSQLstatementwithouthavingtousetheSETcommand
Solution
usenorhtwind
go
SELECT*FROMproductsASt1
WHEREt1.productnameCOLLATESQL_EBCDIC280_CP1_CS_AS='Chai'
--executethiscommandtogetdifferentcollatenaming
--select*from::fn_helpcollations()
Problem
Howtocallastoredprocedurelocatedinadifferentserver
Solution
SETNOCOUNTON
usemaster
go
EXECsp_addlinkedserver'172.16.0.22',N'SQLServer'
go
Execsp_link_publication@publisher='172.16.0.22',
@publisher_db='Northwind',
@publication='NorthWind',@security_mode=2,
@login='sa',@password='sa'
go
EXEC[172.16.0.22].northwind.dbo.CustOrderHist'ALFKI'
go
execsp_dropserver'172.16.0.22','droplogins'
GO
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- SQL 一些小技巧
- SQL一些小技巧
- SQL一些小技巧
- SQL一些小技巧
- SQL一些小技巧
- SQL Server的一些小技巧
- SQL Server的一些小技巧
- 一些小技巧C# 和SQL
- 关于sql优化的一些小技巧
- sql server 中的一些小技巧
- 书写SQL语句的一些小技巧
- DBA日常维护中执行SQL的一些小技巧
- javascript一些小技巧
- 一些小技巧汇总
- SQLServer一些小技巧
- 一些小技巧
- 一些小技巧
- 一些小技巧
- 死锁的问题
- 求救!!!!
- 在页面中嵌入音频和视频的代码
- 防止sql注入的简单方法
- spring和struts整合(转)
- SQL一些小技巧
- 11个笑话领悟人生
- ReportBuilder中占位列的使用
- 引用的各种对象的最大值
- 认识VF--Visual漫谈
- Winpcap(三)
- 一些有用的SQL语句
- F.E.A.R. 编译备忘
- FuncDropColumn(为表删除某字段)