[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

SQL If Statement

Hi,

I have a stored procedure which includes this clause:

    if (select *** FROM ***…..)!='L'
      return

This works okay but I need to change it so that it checks for two values; basically execute return if the result of the select statement is not L or is not S
I’ve tried a couple of approaches but none seem to work? Any suggestions please?
0
andyw27
Asked:
andyw27
1 Solution
 
Dale BurrellCommented:
if (select *** FROM ***…..) not in ('L', 'S')
      return
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Your code it's too short. Could you show more of the Select statement?

I would say that you should have a WHERE clause, so will be more easy. Example:
SELECT Field1, Field2, ..., FieldN
FROM table
WHERE FieldX NOT IN ('L', 'S')

Open in new window

0
 
Vikas GargBusiness Intelligence DeveloperCommented:
Hi,

You can try this one

If(select count(*) from DimAccount where field not in ('L','S')) > 0
return
0
 
John_VidmarCommented:
IF EXISTS
(	SELECT	*
	FROM	SomeTable
	WHERE	SomeField NOT IN ('L', 'S')
)	RETURN

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now