locked
Trouble with an IF statement that uses a bit datatype RRS feed

  • Question

  • Hello. In this statement the field "TUpdate" is a bit. 0=False, 1=True. I'm getting an error. Can anyone help me with where I went wrong with the syntax? Thanks!

    ALTER PROCEDURE dbo.StoredProcedure_PostFeb

     

    AS

     

    CONVERT (TUpdate, int)

     

    IF  (SELECT SUM(TUpdate) FROM tblDetail WHERE TDate BETWEEN  '2/1/2001' AND '2/28/2001') = 0

     

    BEGIN   

     

    CREATE TABLE  #FebPosting (TAcctNo int, FebTotal money)

     

    insert into #FebPosting

     

    SELECT      TAcctNo, SUM(TAmt) as "FebTotal"

     

    FROM          dbo.tblDetail

     

    WHERE      TDate BETWEEN  '2/1/2001' AND '2/28/2001'

     

    GROUP BY TAcctNo

     

     

     

    UPDATE tblGenLed

     

    SET FebAmt = #FebPosting.FebTotal

     

    FROM #FebPosting 

     

    JOIN tblGenLed ON  tblGenLed.AcctNo = #FebPosting.TAcctNo

     

     

    UPDATE tblDetail

    SET TUpdate =1

    WHERE      TDate BETWEEN  '2/1/2001' AND '2/28/2001'

     

    END

    ELSE

     

    PRINT  'Journals Have Already Been Posted to the Ledger ' 

     

     

     

    RETURN

     

     

     

     

     

     

     

     

     

     

     

     

     

    Thursday, November 18, 2010 12:11 PM

Answers

  • what is this syntax?? what you are trying here?

    CONVERT (TUpdate, int)

    It won't work like that. In query, u need to cast that column..

    IF (SELECT SUM(cast(TUpdate as int)) FROM tblDetail WHERE TDate BETWEEN '2/1/2001' AND '2/28/2001') = 0
    • Proposed as answer by Melissa Suciadi Thursday, November 18, 2010 1:21 PM
    • Marked as answer by Kalman Toth Tuesday, November 23, 2010 8:22 AM
    Thursday, November 18, 2010 12:20 PM