[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

nested IF in t-sql

Posted on 1999-11-04
4
Medium Priority
?
2,510 Views
Last Modified: 2008-04-23
Does t-sql support nested ifs or an equvalent.  I am trying to do something like.

if expression
  Begin
    print 'xxx'
    if expression2
       BEGIN
         print 'yyy'
         print 'zzz'
       END
ELSE
  begin
      print 'aaa'
      print 'bbb'
  end
I get 'syntax error near ELSE'  I have not seen an example of such so that would be helpful also
 
0
Comment
Question by:xoxomos
4 Comments
 
LVL 7

Accepted Solution

by:
tchalkov earned 150 total points
ID: 2185250
It does support it, but you have a missimg end before else
0
 
LVL 1

Expert Comment

by:Nael
ID: 2185873
of course it does !!
but as tchalkov said, you missed the last end.
0
 
LVL 7

Expert Comment

by:simonsabin
ID: 2186074
just to help
Your code should be


if expression
  BEGIN
    print 'xxx'
    if expression2
       BEGIN
         print 'yyy'
         print 'zzz'
       END
  END
ELSE
  BEGIN
      print 'aaa'
      print 'bbb'
  END
0
 

Expert Comment

by:manpakhong
ID: 21418576
On situation I have encounted is that the
----------------
if
begin
     if
     begin
           <statement here>
     end
end
-----------------
must have statement between (every begin) and (end part)
otherwise it will have syntax error


Man Pak Hong
manpakhong@hotmail.com
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

612 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