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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server: Msg 156 1

Status
Not open for further replies.

monik22

Programmer
Jul 16, 2003
8
US
Here is where the code fails.... Can anyone tell me why

Expiration =
IF Cardholder.Activation = LockAccess.Activation THEN
LockAccess.Activation
ELSE
Cardholder.Activation
END

-----------------------------------------------------Server: Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'IF'.
Server: Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'THEN'.
 
There is no THEN in SQL... Is that part of SELECT statement or something else?

And according to posted code, simple Expiration = Cardholder.Activation looks enough.

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Sorry it's > not =
-----------------------------------------------------------
SELECT DISTINCT
Cardholder.LastName,
Badge.EncodedID,
Expiration =
IF Cardholder.Activation > LockAccess.Activation
LockAccess.Activation
ELSE
Cardholder.Activation
END
FROM......
 
To correct myself: T-SQL has no IF... THEN. Instead it has CASE WHEN... THEN:

Code:
SELECT DISTINCT
Cardholder.LastName,
Badge.EncodedID,
Expiration =
    CASE WHEN Cardholder.Activation > LockAccess.Activation
	THEN LockAccess.Activation
	ELSE Cardholder.Activation
    END
FROM......

------
"There's a man... He's bald and wears a short-sleeved shirt, and somehow he's very important to me. I think his name is Homer."
(Jack O'Neill, Stargate)
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top