user2927086
user2927086

Reputation: 101

Syntax Error in Stored Procedure with CASE expression

CASE
   WHEN authorizedID = dbo.CUSTOMER_TABLE.authorizedID 
     THEN authorizedID 
     ELSE NULL 
END AS authorizedID,

I want to match authorizedID with different table's column dbo.CUSTOMER_TABLE.authorizedID.

If authorizedID is equals to dbo.CUSTOMER_TABLE.authorizedID then I want to get authorizedID else null.

However I get syntax error for dbo.CUSTOMER_TABLE.authorizedID:

The multi part identifier dbo.CUSTOMER_TABLE.authorizedID could not be bound

Where I miss by writing stored procedure?

Any help will be appreciated.

Upvotes: 0

Views: 167

Answers (1)

Sandr
Sandr

Reputation: 776

In your case the code must be as following:

CASE
   WHEN authorizedID in (select distinct authorizedID from dbo.CUSTOMER_TABLE)
     THEN authorizedID 
     ELSE NULL 
END AS authorizedID

Otherwise you can make left join with this table (dbo.CUSTOMER_TABLE) and, after this, define the CASE condition. In this case performance will be much better.

Upvotes: 1

Related Questions