Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 20th, 2003, 10:39 AM
kshemankar kshemankar is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 3 kshemankar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old December 22nd, 2003, 01:44 PM
Scorpions4ever Scorpions4ever is offline
Mad Rater
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 126 Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level)Scorpions4ever User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 31 m 44 sec
Reputation Power: 7
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.

Reply With Quote
  #3  
Old December 22nd, 2003, 02:14 PM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,760 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 5 h 18 m 17 sec
Reputation Power: 443
why not put them in stored procedures?

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Execute the SQL generated as a Resultset


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway