2012-02-14 61 views
0

我为我的sql代码添加newID后,我的日期无法显示,反正可以纠正我的newID()?首先NEWID(的)是从DBsql语句错误,不能得到随机日期

得到randam数据,我感到我想已经是答案,我将它张贴在明年8小时=)

工作做好

enter code here 
Select [Question],[r1] as [option],[Answer] From ExerciseTable where Question='" + 
((Label)e.Item.FindControl("Label3")).Text + "' AND [r1]!='null' 
UNION 
Select [Question],[r2] as [option],[Answer] From ExerciseTable where Question='" + 
((Label)e.Item.FindControl("Label3")).Text + "' AND [r2]!='null' 
UNION 
Select [Question],[r3] as [option],[Answer] From ExerciseTable where Question='" + 
((Label)e.Item.FindControl("Label3")).Text + "' AND [r3]!='null' 

后,我加入NEWID()它没有工作

Select [Question],[r1] as [option],[Answer] From ExerciseTable where Question='" + 
((Label)e.Item.FindControl("Label3")).Text + "' AND [r1]!='null' order by newID() 
UNION 
Select [Question],[r2] as [option],[Answer] From ExerciseTable where Question='" + 
((Label)e.Item.FindControl("Label3")).Text + "' AND [r2]!='null' order by newID() 
UNION 
Select [Question],[r3] as [option],[Answer] From ExerciseTable where Question='" + 
((Label)e.Item.FindControl("Label3")).Text + "' AND [r3]!='null' order by newID() 
+0

什么是'newID()'? – V4Vendetta 2012-02-14 04:28:12

+0

首先格式化非常糟糕,其次是SQL INJECTION,第三,只有联合的最后部分需要order by子句。 – 2012-02-14 04:28:30

+1

@ V4Vendetta newID是随机获取sql数据 – 2012-02-14 04:31:36

回答

0

这是我想要的最新答案。

Select * from (Select [Question],[r1] as [option],[Answer] 
From ExerciseTable where Question='" + ((Label)e.Item.FindControl("Label3")).Text + "' AND [r1]!='null' 
UNION 
Select [Question],[r2] as [option],[Answer] 
From ExerciseTable where Question='" + ((Label)e.Item.FindControl("Label3")).Text + "' AND [r2]!='null' 
UNION 
Select [Question],[r3] as [option],[Answer] 
From ExerciseTable where Question='" + ((Label)e.Item.FindControl("Label3")).Text + "' AND [r3]!='null')t order by Newid()