Results 1 to 3 of 3

Thread: If else in a Storep Procedure

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    16

    Question

    Hi

    I'm trying with the an sql query get a recordset and
    to return a name for ex

    select name,adress,number1, number2 , number3

    if numer1 + number2 > 0
    begin

    select 'BiggerthanZero' as ReturnName
    end
    else
    begin

    select 'LessThanZero' as ReturnName
    end

    FROM TableName

    this doesn't work what im a doing wrong or is
    it impossible to return a recordset and the 'ReturnName'

    Micke

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    617

    ...

    Q.
    1. Your select, does it return more than 1 record?

    do you expect it to?

    In any case, you could return it as part of the recordset

    select name, add,num1, num2, num1 + num2 as desiredfield

    and check your recordset later one for desired field

    if RS.fields("DesiredField") > 0 then


    assuming RS is your recordset..

    good luck


  3. #3
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    I'm suprised it will even compile.

    You have a from clause just hanging out there by itself. You should consider using a return value and output paramter instead.

    What you have there if it were properly written, would never return your name,adress,number1, number2 , number3 values at all. Ever.

    Code:
    --This gets your initial dataset, but it will not return it because you are doing another select later on.  
    --Also, it will only check the first record returned from this initial dataset unless you use a cursor.
    
    select name,adress,number1, number2 , number3 FROM TableName 
    
    if number1 + number2 > 0 
     begin 
        select 'BiggerthanZero' as ReturnName 
     end 
    else 
     begin 
        select 'LessThanZero' as ReturnName 
     end
    It would probably help if you mentioned what you were trying to do with the proc..
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width