日期:2014-05-17 浏览次数:20489 次
CREATE PROC addtimetable(@number INT) AS
DECLARE @i INT;
SET @i=0;
WHILE @i<@number
BEGIN
CASE
WHEN CAST(CEILING(RAND(CHECKSUM(NEWID()))*10) AS INT)%2=0
THEN
INSERT INTO timetable VALUES ('1', '2', '3', '4', '5', '6')
ELSE
INSERT INTO timetable VALUES ('1', '2', '3', '7', '8', '9')
END CASE
SET @i=@i+1
END
CREATE PROC addtimetable(@number INT) AS
DECLARE @i INT;
SET @i=0;
WHILE @i<@number
BEGIN
if CAST(CEILING(RAND(CHECKSUM(NEWID()))*10) AS INT)%2=0
INSERT INTO timetable VALUES ('1', '2', '3', '4', '5', '6')
ELSE
INSERT INTO timetable VALUES ('1', '2', '3', '7', '8', '9')
SET @i=@i+1
END
1、Case When 一般用于赋值语句;
2、End Case 也有语法问题;
eg.
CREATE PROC addtimetable(@number INT) AS
DECLARE @i INT;
DECLARE @sql varchar(2000)
set @sql=''
SET @i=0;
WHILE @i<@number
BEGIN
set @sql=
CASE
WHEN CAST(CEILING(RAND(CHECKSUM(NEWID()))*10) AS INT)%2=0
THEN
'INSERT INTO timetable VALUES (''1'', ''2'', ''3'', ''4'', ''5'', ''6'')'
ELSE
'INSERT INTO timetable VALUES (''1'', ''2'', ''3'', ''7'',&n