Explore Courses Blog Tutorials Interview Questions
0 votes
in SQL by (6.1k points)
I attempted searching around, however, I couldn't find anything that would help me out.

I'm attempting to do this in SQL:

I know that I shouldn't have to put '= @locationID' at the end of each one, but I can't get the syntax even close to being correct. The SQL keeps on complaining about my '=' on the first WHEN line...

How will I do this?

1 Answer

0 votes
by (12.7k points)
edited by

You can use the following code:

declare @locationType varchar(50);
declare @locationID int;

SELECT column1, column2
FROM viewWhatever
@locationID = 
  CASE @locationType
      WHEN 'location' THEN account_location
      WHEN 'area' THEN xxx_location_area 
      WHEN 'division' THEN xxx_location_division 

Looking for a SQL Tutorial? Join the SQL Course to gain more knowledge on SQL.

Related questions

Browse Categories