SQL Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fordyce
    New Member
    • Nov 2011
    • 1

    SQL Query

    I really hope someone would help me. I had this query:

    "Select distinct DVD.DVDid,Rent_ Detail.RentNo,T itle,Num_of_DVD ,(getdate()-RentDate)+1 As RentPeriod,(CAS E WHEN RentPeriod>5 THEN (RentPeriod-5)*500 ELSE RentPeriod*0 END) As Fine From Member,Rental,D VD,Rent_Detail Where DVD.DVDid=Rent_ Detail.DVDid And Rental.RentNo=R ent_Detail.Rent No And Member.MemberID =Rental.MemberI D And Member.MemberID ='" & ComboBox1.Text & "' AND Rent_Detail.DVD id='" & DGV1.Rows(e.Row Index).Cells(0) .Value & "' AND Rent_Detail.Num _of_DVD>0"

    Now my question is, there are error saying that invalid column from 3 RentPeriods in CASE, but I use those just to create a column name "fine". Why is that?
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can't refer to a calculated field in the same SQL level in which it was created.

    Comment

    • gpl
      New Member
      • Jul 2007
      • 152

      #3
      In the case statement, replace 'rentperiod' by the definition of rentperiod from the previous column

      Comment

      • pooja rani
        New Member
        • Nov 2011
        • 2

        #4
        keyword as must be in either lower or upper but not As.

        Comment

        Working...