|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Execute the SQL generated as a Resultset
Hi,
I am writing following code: SET QUOTED_IDENTIFIER OFF Drop Table #T1 Create Table #T1 (UID int, Qid int, DL int) Insert Into #T1 SELECT QB.Unit_No,QB.QID,QB_MCQ.Diff_Level FROM QB INNER JOIN QB_MCQ ON QB.QID = QB_MCQ.QID WHERE (QB.TEAM_ID =1) Order By Unit_No,Diff_Level Drop Table #T2 Create Table #T2 (UID int, RowCnt Decimal(28,9)) INSERT INTO #T2 SELECT UID,Count(*) as RowCnt FROM #T1 Group By UID Update #T2 Set RowCnt = round((0.4 * RowCnt),0) SELECT * FROM #T2 SELECT "SELECT TOP " + rtrim(RowCnt) + " * FROM #T1 A , #T2 B WHERE A.UID = B.UID Group By A.UID,RowCnt " FROM #T2 After running this code I get following output: SELECT TOP 10.000000000 * FROM #T1 A , #T2 B WHERE A.UID = B.UID Group By A.UID,RowCnt SELECT TOP 4.000000000 * FROM #T1 A , #T2 B WHERE A.UID = B.UID Group By A.UID,RowCnt Now, Instead of getting these two SQL statements, I want to execute these statements and get their resultant output. How do I achieve that? Thanks in advance |
|
#2
|
|||
|
|||
|
You could use the EXECUTE command to execute a SQL command from a string.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. |
|
#3
|
||||
|
||||
|
why not put them in stored procedures?
|
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Execute the SQL generated as a Resultset |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|