Solved

SQL IF statement

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQl server restarts itself 6 33
configure service broker on all databases 2 77
Analysis of table use 7 42
Help with stripping out character in SQL LEFT/RIGHT/REPLACE 2 40
If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now