Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-07-2009
Member
 
Join Date: Apr 2009
Posts: 65
Want to create if statement in SQL

I'm creating a stored procedure to return search results where some of the parameters are optional. In PL/SQL if we write select statement with INTO clause it may return two exceptions NO_DATA_FOUND or TOO_MANY_ROW. I want an "if statement" in my where clause but can't get it working. The where clause should filter by only the non-null parameters. How to check the Average sequential Read time by STAT and STAD.
Reply With Quote
  #2  
Old 29-07-2009
Member
 
Join Date: Apr 2008
Posts: 193
Re: Want to create if statement in SQL

IF statements can be used to conditionally enter into some logic based on the status of a condition being satisfied. SQL Server provides a mechanism for returning different values in a SELECT clause based on Boolean conditions. The IF statement is logically equivalent to a CASE statements with a searched-case-statement-when clause. The IF statement supports the use of optional ELSE IF clauses and a default ELSE clause. An END IF clause is required to indicate the end of the statement.
Reply With Quote
  #3  
Old 29-07-2009
Member
 
Join Date: Mar 2008
Posts: 433
Re: Want to create if statement in SQL

Just so you understand, IF is procedural code in T-SQl. It canot be used in an insert/update/delete/select statement it can only be used to determine which of two statements you want to run. you can handle Too_Many_Rows exception when you are writing into a PL/SQL block SELECT...INTO statement.
Reply With Quote
  #4  
Old 29-07-2009
Member
 
Join Date: Jan 2006
Posts: 211
Re: Want to create if statement in SQL

SQL Server compares this value to the expression and when the values match, it returns the THEN clauses [return value]. A big problem arises though when you want to optionally filter for a column that is also nullable... if the data in the column is null for a given row If none of the WHEN clauses equates to true, SQL Server returns the [return value] in the optional ELSE clause. If the ELSE clause is omitted and no value is matched, NULL is returned. One downside of If statements is that if there are a number of different actions that must be taken based on some variable value, the number of If statements can explode, leading to bloated, unreadable code.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Want to create if statement in SQL"
Thread Thread Starter Forum Replies Last Post
how to create a If-Else statement in C# Mustafa k Software Development 3 24-01-2011 05:07 PM
Store procedure with 10 select statement.how to create datatable in dotnet? itechsasi Software Development 1 16-08-2010 02:03 PM
How to use Else and Else If Statement in PHP? Orton Software Development 5 05-03-2010 06:49 AM
How to use If statement in PHP? Deabelos Software Development 4 09-02-2010 06:14 AM
What is the difference between while statement & do statement? Athos Software Development 4 25-02-2009 08:52 PM


All times are GMT +5.5. The time now is 08:08 PM.