Solved

SQL IF statement

Posted on 2007-12-06
3
199 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

615 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