Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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
WHERE
@locationID = 
  CASE @locationType
      WHEN 'location' THEN account_location
      WHEN 'area' THEN xxx_location_area 
      WHEN 'division' THEN xxx_location_division 
  END

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

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Sep 29, 2019 in Java by Shubham (3.9k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...