2012-02-14 4 views
0

私のSQLコードのnewIDを追加した後、私の日付は表示することはできませんとにかく、私のnewID()を修正することはできますか? )私はすでに欲しい答えを得るDBsqlステートメントエラー、カントランダム日付を得る

からrandamデータを取得するために、私は次の8時間4,000の=でそれを掲示するために最初にすべてのNEWID(の)です

作業も

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

+0

まず第一に書式は本当に悪いです。第二にSQL INJECTIONです.3番目には、連合の最後の部分だけがorder by節を必要とします。 –

+1

@ V4Vendetta newIDはランダムにSQLデータを取得します –

答えて

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()