March 11, 2004 at 8:33 am
I'm trying to use a variable to determine how many of the top I need. I get a compile error when I try it. It works fine if I replace @orig_free_qty w/ a hard-coded value. Am I stuck w/ using hard-code?
UPDATE @Orig_Calendar Set free_day = 1 Where orig_start in (Select Top @orig_free_qty orig_start from @Orig_Calendar order by orig_start desc)
March 11, 2004 at 8:45 am
You will need to either use dynamic SQL or "SET ROWCOUNT @orig_free" instead of TOP. If you use SET ROWCOUNT, don't forget to set it back to 0 after the statements.
--Jonathan
March 11, 2004 at 9:05 am
When I do this:
SELECT @orig_free_qty = 9
SET ROWCOUNT @orig_free_qty
UPDATE @Orig_Calendar Set orig_free_day = 1
I get this:
Invalid argument for SET ROWCOUNT. Must be a non-null non-negative integer.
March 11, 2004 at 9:15 am
What data type is @orig_free_qty?
--Jonathan
March 11, 2004 at 9:19 am
@orig_free_qty numeric(4),
March 11, 2004 at 9:35 am
Can you use that information along with the error message to find the problem?
--Jonathan
March 11, 2004 at 1:35 pm
SET ROWCOUNT expects an INTEGER datatype, not a numeric(4). Changing your datatype to integer will resolve the problem.
March 11, 2004 at 2:00 pm
Hm, Jonathan, that reminds me of those quizes on TV where you have to tell your name, and if you're right, win $1,000.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
March 11, 2004 at 7:41 pm
Let's not forget our "other DBMS" colleagues.
With "anOther DBMS", integer is an alias for a particular definition of numeric, so Rob was maybe quite justifiably stumped.
Cheers,
- Mark
March 12, 2004 at 12:49 am
Me bad! No offense meant!
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply