qq70191 发表于 2016-11-7 01:33:35

Sql Server每日一练-在select语句中使用top的一些小技巧

  在select语句中使用top的一些小技巧
  
  It's well-known.Microsoft SQL Server 7.0增加了一个语句top,可以限制返回的记录数。但是在使用的时候,有时候会遇到一些问题。 比如希望返回前三名的比分,但是第三名有并列的,使用select top 3 * from table order by score的话就只能返回三条记录,在这样的情况下,就可以使用
select top 3 with ties * from table order by score
还有,有的时候我不希望出现重复的记录,那么可以使用select distinct top 3
* from table order by score
  
  如何操作SQL的TXT字段
  
  1、在从SQL的 TXT字段中获取数据时,不能用缺省的forward-only光标。
  2、当大量的插入时,要用 INSERTTEXT 和 UPDATETEXT命令。
  以下有例子:
  <!-- #INCLUDE VIRTUAL="adovbs.inc" -->
  <%
  Set MyCon=Server.CreateObject("ADODB.Connection")
  Set RS=Server.CreateObject("ADODB.RecordSet")
  MyCon.Open "DSN=MyDSN;UID=ME;PWD=Secret"
  ' Create a SQL Insert String
  MySQL="INSERT MyTable (MyTextColumn) VALUES ('Some really long
string')"
  ' Insert the string into the table named "MyTable"
  MyCon.Execute MySQL
  ' Open the RecordSet with a Static Cursor for a TEXT Column
  RS.Open "SELECT MyTextColumn FROM MyTable",MyCon,adOpenStatic
  Response.Write(RS("MyTextColumn"))
  RS.Close
  MyCon.Close
  %>
页: [1]
查看完整版本: Sql Server每日一练-在select语句中使用top的一些小技巧