Isabella
---- I fell upon the thorn of life, I bleed.
posts - 28,  comments - 14,  trackbacks - 0
06 2007 档案
交叉查询
摘要: (一)USE NorthwindselectOrderID,count(case when Quantity between 20 and 30 then ProductID end) as '20-30',count(case when Quantity between 30 and 40 then ProductID end) as '30-40',count(case when Quanti...阅读全文
posted @ 2007-06-06 15:06 李昀璟 阅读(168) | 评论 (0) 编辑
嵌套游标及动态SQL
摘要: USE Northwinddeclare Order_cursor cursor forSELECT OrderID from Ordersopen Order_cursordeclare @OrderID as INTfetch next from Order_cursor into @OrderIDwhile(@@fetch_status =0)beginPRINT 'OrderID' + S...阅读全文
posted @ 2007-06-05 16:54 李昀璟 阅读(580) | 评论 (1) 编辑
Dynamic SQL
摘要: 如果你经常关注SQL Server的NewsGroups,你会发现人们经常会问为什么我不能运行这样的SQL语句:SELECT * FROM @tablenameSELECT @colname FROM tblSELECT * FROM tbl WHERE x IN (@list)In many cases someone says "use dynamic SQL" and with a simp...阅读全文
posted @ 2007-06-05 16:13 李昀璟 阅读(462) | 评论 (0) 编辑
 随机选择数据库记录的方法
摘要: 选择从10到15的记录select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc  随机选择数据库记录的方法(使用Randomize函数,通过SQL语句实现)  对存储在数据库中的数据来说,随机数特性能给出上面的效果,但它们可能太慢了些。你不能要求ASP“找个随机数...阅读全文
posted @ 2007-06-05 11:51 李昀璟 阅读(595) | 评论 (0) 编辑
得到用户表结构的SQL语句
摘要: 查询系统表INFORMATION_SCHEMA.TABLES得到所有用户表结构:SELECT T.TABLE_SCHEMA as [TableOwner],T.TABLE_NAME as [TableName],C.COLUMN_NAME as [ColumnName],C.DATA_TYPE as [DataType],C.CHARACTER_MAXIMUM_LENGTH as [Size],C...阅读全文
posted @ 2007-06-05 11:12 李昀璟 阅读(646) | 评论 (1) 编辑