tags:

views:

105

answers:

3

I have two ints: @RecurremceTemp and @WeekDifference

The following line errors:

PRINT @WeekDifference >= @RecurrenceTemp

with Incorrect syntax near '>'

And won't execute.

Can someone please tell me how to write such a boolean expression to include in a Select statement i.e.:

Select * 
FROM TableX 
WHERE somevariable = x 
and @WeekDifference >= @RecurrenceTemp
A: 

Return -1, 0, or 1 from a CASE statement, depending on the comparison. In SQL Sevrer, there is no boolean data type. The nearest data type is BIT, which can have a value of 1, 0 or null.

EDIT:

Your SQL statement

Select * 
FROM TableX 
WHERE somevariable = x 
and @WeekDifference >= @RecurrenceTemp

will select all fields from TableX where somevariable = x and the WeekDifference variable value is greater than or equal to the RecurrenceTemp variable value. Is that not what you want?

Russ Cam
A: 

Your query ought to work just fine.

The reason that the print statement fails is due to the fact that SQL Server treats the results of a boolean expressions very differently than other data types. See Operators:

Unlike other SQL Server data types, a Boolean data type cannot be specified as the data type of a table column or variable, and cannot be returned in a result set.

Andrew Hare
+1  A: 

Predicates cannot be used in expressions, only in IF and WHILE and CASE WHEN:

PRINT CASE WHEN @WeekDifference >= @RecurrenceTemp THEN 1 ELSE 0 END
Tommy Carlier