Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is it possible
Message
From
12/02/2013 14:59:05
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2008
Application:
Desktop
Miscellaneous
Thread ID:
01565799
Message ID:
01565807
Views:
46
Ok, here's what I'm trying (I start with the simplest and add), the simplest
Declare @TB int
Select @TB = TypeB from ExpFrameWork where Category = '40'
print @TB    && prints 5 - like I'd expect it to.

Select top @TB from ExpMaster where Category = '40' and Difflet = 'B'    
*The above has the red line under it and says Incorrect syntax near @TB.  Expecting REAL, INTEGER, NUMERIC or '('
If I replace @TB with (@TB) it gives me 'Incorrect syntax near from'
Perhaps 'expression' isn't meaning what I think it means?


>You can use expression in top clause
>
>SELECT TOP (expression) ...
>
>
>>Before I make myself completely insane trying to do it, say I have a TestFrameWork table that looks like
>>
>>Cat     TypeB      TypeC     TypeD     TypeE
>>----------------------------------------------------------------
>>40          5              3             6            4
>>41
>>.
>>.
>>.
>>
>>
>>Where the numbers 5,3, etc are the number of records I need of each Cat and Type and will change periodically but I can't predict what they will be; the 'B','C','D','E' are the difficulty letters (DiffLet). But I need to be able to pull x number of records based on Cat and DiffLet
>>
>>I know we can say
>>
>>Select top 5 from (filename) where Cat = '40' and DiffLet = 'B'
>>Union
>>(Select top 3 from (filename) where Cat = '40' and DiffLet = 'C'
>>Union
>>...
>>
>>
>>
>>but is it possible to say
>>
>>Select top TestFrameWork.TypeB from (filename) where Cat = '40' and DiffLet = 'B'
>>
>>?
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform