随即抽取问题可以用
select top 1 * from tableA order by newID()得到时间可以用
select getdate()

解决方案 »

  1.   

    1、做一个存储过程,关于随机抽题的,题有根据难,中,易分,抽过的题不可再抽。
    select * from (
    select top 1 * from tableA where 难度='难' order by newID() ) a
    union all
    select * from (
    select top 1 * from tableA where 难度='中' order by newID() ) a
    union all
    select * from (
    select top 1 * from tableA where 难度='易' order by newID() ) a
    2、如何在C\S结构下得到数据库服务器的当前时间(最好能给出C#中的实现代码)。
    GETDATE
    按 datetime 值的 Microsoft® SQL Server™ 标准内部格式返回当前系统日期和时间。语法
    GETDATE ( )返回类型
    datetime注释
    日期函数可用在 SELECT 语句的选择列表或用在查询的 WHERE 子句中。在设计报表时,GETDATE 函数可用于在每次生成报表时打印当前日期和时间。GETDATE 对于跟踪活动也很有用,诸如记录事务在某一帐户上发生的时间。示例
    A. 用 GET DATE 返回当前日期和时间
    下面的示例得出当前系统日期和时间:SELECT GETDATE()
    GO下面是结果集:-------------------------
    July 29 1998   2:50    PM(1 row(s) affected)B. 在 CREATE TABLE 语句中使用 GETDATE
    下面的示例创建 employees 表并用 GETDATE 给出员工雇佣时间的默认值。USE pubs
    GO
    CREATE TABLE employees
    (
     emp_id char(11) NOT NULL,
     emp_lname varchar(40) NOT NULL,
     emp_fname varchar(20) NOT NULL,
     emp_hire_date datetime DEFAULT GETDATE(),
     emp_mgr varchar(30)
    )
    GO
      

  2.   

    create proc procName
    @1 int,
    @2 int,
    @3 int
    asdeclare @a varchar(8000)
    set @a='
    select * from (
    select top '+cast(@1 as varchar(10))+' * from tableA where 难度=''难'' order by newID() ) a
    union all
    select * from (
    select top '+cast(@2 as varchar(10))+' * from tableA where 难度=''中'' order by newID() ) a
    union all
    select * from (
    select top '+cast(@3 as varchar(10))+' * from tableA where 难度=''易'' order by newID() ) a
    '
    exec(@a)
      

  3.   

    create proc procName
    @1 int,
    @2 int,
    @3 int
    asdeclare @a varchar(8000)
    set @a='
    select * from (
    select top '+cast(@1 as varchar(10))+' * from tableA where 难度=''难'' order by newID() ) a
    union all
    select * from (
    select top '+cast(@2 as varchar(10))+' * from tableA where 难度=''中'' order by newID() ) a
    union all
    select * from (
    select top '+cast(@3 as varchar(10))+' * from tableA where 难度=''易'' order by newID() ) a
    '
    exec(@a)
    go--调用:exec procName 10,1,4
      

  4.   

    大力,你的程序不行,我运行错误啊!
    alter procedure sjsc
    @a int,
    @b int,
    @c int
    as
    declare @g varchar(8000)
    set @g='
    select * from (
    select top '+cast(@a as varchar(10))+' * from Question where que_difficulty='+'1'+' order by NEWID()) s
    union all
    select * from (
    select top '+cast(@b as varchar(10))+' * from Question where que_difficulty='+'2'+' order by NEWID()) s
    union all
    select * from (
    select top '+cast(@c as varchar(10))+' * from Question where que_difficulty='+'3'+' order by NEWID()) s
    '
    exec(@g)
    goexec sjsc 1,1,1
    我的表是
    create table dbo.Question (
       cou_no               numeric(18)          not null,
       teau_no              numeric(18)          not null,
       que_no               numeric(18)          not null,
       que_type             char(1)              null
            constraint CKC_QUE_TYPE_QUESTION check (que_type is null or ( que_type in ('1','2') )),
       que_score            real                 null,
       que_difficulty       char(1)              null
            constraint CKC_QUE_DIFFICULTY_QUESTION check (que_difficulty is null or ( que_difficulty = '3' or que_difficulty in ('1','2') )),
       que_picture          image                null,
       que_content          text                 null,
       que_createtime       datetime             null,
       que_modifytime       datetime             null,
       que_memo             varchar(200)         null,
       constraint PK_QUESTION primary key clustered (que_no, teau_no, cou_no)
    )
    go
    大力请帮忙看看,谢谢