How to access column data outside SELECT statement

  • Simple problem - I simply want to access the value of a column after the SELECT statement. Is this possible? I understand that rows are being returned and this might pose a problem but in my example either no rows are returned or only one row is returned.

    Should I use a cursor? Can I get row count from loading the cursor? Any other techniques would be appreciated.

    Thanks in advance

    Mike

    -- Local Variables

    declare @Dayin int = 0

    ,@DayGood char(1) = 'y'

    ,@LengthofStay int = 1

    ,@xx int

    SELECT RMS_FromDate

    ,RMS_Todate

    ,RMS_Days

    ,RMS_Description

    FROM ResMinimumStay

    WHERE RMS_ResortId = @ResortID and RMS_RoomType = @RoomType and (@Datein >= RMS_FromDate and @Datein <= RMS_ToDate);

    IF @@RowCount = 1 and @LengthofStay < RMS_Days

    print 'good'

    else print 'BAD'

  • -- Local Variables

    declare @Dayin int = 0

    ,@DayGood char(1) = 'y'

    ,@LengthofStay int = 1

    ,@xx int

    ,@RMSDays int -- new variable

    SELECT @RMSDays = RMS_Days

    FROM ResMinimumStay

    WHERE RMS_ResortId = @ResortID and RMS_RoomType = @RoomType and (@Datein >= RMS_FromDate and @Datein <= RMS_ToDate);

    IF @LengthofStay < @RMSDays

    print 'good'

    else print 'BAD'

    Does that get you what you need?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Thanks, it is beautiful. Little tricks I need to know come only with time and asking the question.

    Thanks again. Mike

  • You're welcome.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply