Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL IF statement

Posted on 2007-12-06
3
Medium Priority
?
200 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 1000 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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 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