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

    Unanswered: Problems with wildcards

    Hi all,

    I am creating an ASP.NET site, and I'm having lots of issues trying to get wildcards to work with the following query:

    Code:
    DECLARE @Status varchar
    DECLARE @AssignedTo int
    DECLARE @AppID int
    
    SELECT dbo.Issue.IssueID, dbo.Issue.ReportedBy, dbo.Issue.ShortDescription, dbo.Issue.DateReported, dbo.Issue.Status, dbo.Priority.Description AS Priority, 
           dbo.Application.Application
    FROM dbo.Issue INNER JOIN
         dbo.Priority ON dbo.Issue.Priority = dbo.Priority.PriorityCode INNER JOIN
         dbo.Application ON dbo.Issue.Application = dbo.Application.ApplicationID
    WHERE (dbo.Issue.Status LIKE '%' + @Status) AND (dbo.Issue.AssignedTo = @AssignedTo) AND (dbo.Application.ApplicationID LIKE '%' + @AppID)
    ORDER BY dbo.Priority.PriorityCode
    When running this through query analyser I get the error:

    Server: Msg 245, Level 16, State 1, Line 5
    Syntax error converting the varchar value '%' to a column of data type int.
    Could someone help me understand this please?

    Thanks
    <- Hides behind a rock.

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    this seems a little self explanatory. the column you are comparing to is an integer field and wildcards are used to search character fields.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Sep 2005
    Posts
    240
    Quote Originally Posted by Thrasymachus
    this seems a little self explanatory. the column you are comparing to is an integer field and wildcards are used to search character fields.
    Is there an alternative solution to get around this problem?

    I want to have a query that will bring back all records, else bring back whatever is in the variable.
    <- Hides behind a rock.

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You could take a look into the Convert function...
    http://doc.ddart.net/mssql/sql70/ca-co_1.htm
    George
    Home | Blog

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Do you mean: if the variable is omitted then return everything - otherwise return results where the variable = status?
    George
    Home | Blog

  6. #6
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    In that case, you want to look up CASE for T-SQL.

Posting Permissions

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