Solved

SQL IF statement

Posted on 2007-12-06
3
198 Views
Last Modified: 2010-03-19
I would like to create a stored procedure which pulls different data depending on the @Type that i provide.

Is there a way to use "IF" logic within an SQL statement?
0
Comment
Question by:jjexpert1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 250 total points
ID: 20419523
Yes
use like this

If @Type = 'somevalue'
Begin
        'do statement
        'do statement
End
Else
Begin
        'do statement
        'do statement
End
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20419541
Or Try using Case @Type = 'somevalue' Then 'something' Else 'something' End
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20419543
Sorry it should be like
Case When @Type = 'somevalue' Then 'something' Else 'something' End
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question