Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    240

    Unanswered: Query: IIf and parameter

    Hi,

    Is it possible to create a query with an IIf Function but using a parameter in the expression?

    This is what I'm trying to do, except it doesn't work:
    Code:
    SELECT     Related_Area_Id, Course_Code, Course_Public_Title, Course_Level, Course_WBLTTG_Only
    FROM         dbo.Course
    WHERE     (Related_Area_Id = @CurriculumArea) AND (Course_Level = @CourseLevel) AND (Course_WBLTTG_Only = IIf(@Apprenticeship = True, 1, 0))
    Are there any other solutions?

    Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you may have to play around with @Apprenticeship to get the condition right, i don't think SQL Server supports "equals True"
    Code:
    SELECT Related_Area_Id
         , Course_Code
         , Course_Public_Title
         , Course_Level
         , Course_WBLTTG_Only
      FROM dbo.Course
     WHERE Related_Area_Id = @CurriculumArea
       AND Course_Level = @CourseLevel
       AND Course_WBLTTG_Only = 
              CASE WHEN @Apprenticeship = 'T'
                   THEN 1 ELSE 0 END
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2005
    Posts
    240
    Thanks, forgot about the Case function.

Posting Permissions

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