Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can an IF be used with CASE? 1

Status
Not open for further replies.

willydude

Programmer
Oct 24, 2006
123
US
I get “incorrect syntax” error msg’s with the following.
In actual use, if one of the following (AW, PR, TS, SW, RW or GS) is not entered as the StepCode, then error msg. For brevity's sake, not all have been listed below for Case selection example.

Code:
--Beginning the use of CASE statements
Begin  
Select StepCode =
	case StepCode
		when 'PR' 
	then  
--begin  --"incorrect syntax near IF"	
IF @PrevailingWage is null or @PrevailingWage = 0
	begin   --must have a prevailingWage value
	set @Message = 'Prevailing Wage Required'
	set @Continue = 0
	end

IF @Standard is null or @Standard = 0
	begin --must have a Standard value
	set @Message = 'Standard Required'
	set @Continue = 0
	end
--end

WHEN 'TS' --"incorrect syntax near WHEN"
then   
IF @PrevailingWage is null or @PrevailingWage = 0
	begin   --must have a prevailingWage value
	set @Message = 'Prevailing Wage Required'
	set @Continue = 0
	end

--Can Not Use Guaranteed Step Wage With This Step Code
if @GuaranteedStepWage is NOT null or @GuaranteedStepWage <> 0
	begin 
	set @Message = 'Can Not Use Guaranteed Step Wage With This Step Code'
	set @Continue = 0
	end

--cannot use standard with this step code
if @Standard is NOT null or @Standard <> 0
	begin
	set @Message = 'Cannot Use Standard With This Step Code'
	set @Continue = 0
	end
--end

when 'AW' --"incorrect syntax near WHEN"
then 
	if @PrevailingWage is NOT null or @PrevailingWage > 0
	begin
	set @Message = 'Cannot Use Prevailing Wage With This Step Code'
	set @Continue = 0
	end

if @Standard is NOT null or @Standard <> 0
	begin
	set @Message = 'Cannot Use Standard With This Step Code'
	set @Continue = 0
	end

--Can Not Use Guaranteed Step Wage With This Step Code
if @GuaranteedStepWage is NOT null or @GuaranteedStepWage <> 0
	begin 
	set @Message = 'Can Not Use Guaranteed Step Wage With This Step Code'
	set @Continue = 0
	end
else
	begin
	set @Message = 'You did not enter a proper step code.'
	end
end

Thanks,

Bill
 
no id cannot beused inside a case statement. If is procedural and so must be used outside select statments only.

"NOTHING is more important in a database than integrity." ESquared
 
They are not ID's, as in Identity, but they are PK's.

PK's not allowed?

Thanks,

Bill
 
I mean IF not id sorry a slip of the keyboard

"NOTHING is more important in a database than integrity." ESquared
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top