Solved

SQL IF statement

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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

23 Experts available now in Live!

Get 1:1 Help Now