SQL doesn't let you use variables that way.
What I would do is (a) figure out if a cursor is really needed for this or if it can be replaced with set-based code, (b) if a cursor is needed, create it with a Union All query based on a Where, instead of using If.
DECLARE RandomUser_CURSOR CURSOR
LOCAL FORWARD_ONLY KEYSET SCROLL_LOCKS
FOR
select *
from TableA
where @bCustom = 0
union all
select *
from TableB
where @bCustom != 0
FOR UPDATE
OPEN RandomUser_CURSOR
FETCH NEXT FROM RandomUser_CURSOR INTO
@Col1, @Col2, @Col3
WHILE @@FETCH_STATUS = 0
BEGIN
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon