0

I need this to return a boolean value if the following condition is met but I keep getting syntax errors

declare @OverLimit bit = 0  
declare @var int

set @var = Select count(pkid)
             From Clicks

If @var > 720,000 then
  @OverLimit = 1

Select @OverLimit
1
  • 2
    what syntax error do you get ? Where ? Commented Jan 3, 2011 at 19:45

5 Answers 5

1

Here is a version with the syntax errors rectified:

declare @OverLimit bit = 0 declare @var int

set @var = (Select count(pkid) From Clicks)

If @var > 720000 SET @OverLimit = 1

Select @OverLimit

The problems were:

The set - select statement needed brackets

The comma is reserved (removed it)

Sign up to request clarification or add additional context in comments.

Comments

1

You might try reading the SQL manual, and the error messages and dealing with the underlying syntax issues:

declare @OverLimit bit
set     @Overlimit = 0

declare @var int
select  @var = count(pkid) From Clicks

If @var > 720000 set @OverLimit = 1

select @OverLimit

Comments

1

Try this:

declare @OverLimit bit = 0
declare @var int

SELECT @var = count(pkid) From Clicks

If @var > 720000 SET @OverLimit = 1

Select @OverLimit

Or alternatively:

SELECT CASE WHEN COUNT(pkid) > 720000 THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END AS Overlimit
FROM Clicks

Comments

0

Wishing I had access to SQL as I write this to test: but isn't this wrong

set @var = Select count(pkid) From Clicks

try

 Select @var=count(pkid) From Clicks

Comments

0

Since you didn't list specific errors, here are some lines I would recommend fixing.

  • Change from:

    set @var = Select count(pkid) from Clicks
    

    To:

    set @var = (Select count(pkid) from Clicks)
    
  • remove the comma from 720,000

  • remove "then" from If statement and insert "Set":

    If @var > 720000
       set @OverLimit = 1
    

1 Comment

If you post code or XML, please highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.